ResourceString (C++)
Contents
Description
This example shows how to load Delphi resource strings from a C++ application.
To build and test this example:
- Create a Delphi package where you can define a resource string:
- Create a new Delphi package, and save it as "DelphiPackage".
- Add a new Delphi unit to your package, and save this unit as "DelphiUnit".
- Create a C++ console application to load and show your Delphi resource string:
- On the Projects Window, right-click your project group and select Add New Project.
- On the New Items dialog box, select C++Builder Projects on the tree view and, on the list of C++Builder projects, select Console Application and click OK.
- On the New Console Application dialog box that opens, click OK to use the default C++ console application settings.
- Save your main C++ file as "main.cpp", your precompiled header file as "CppApplicationPCH.h", and your project as "CppApplication".
- Select Project > Options > C++ Linker and enable the "Link with the Delphi Runtime Library" option.
Code
Add a "Message" resource string to the DelphiUnit.pas file:
unit DelphiUnit;
interface
resourcestring
Message = 'This is a Delphi resource string.';
implementation
end.
Then right-click your DelphiPackage project on the Project Manager and select Build.
Add the generated Delphi package library file to your C++ console application:
- Right-click your CppApplication project on the Project Manager and select Add.
- On the dialog box that opens, select the DelphiPackage.lib file that you previously built and click OK. You may find this file inside "C:\Users\Public\Documents\Embarcadero\Studio\23.0\Dcp".
- Note: If you cannot see the expected file, ensure that the file filter in the dialog box is "Any file (*.*)".
In your main.cpp file:
- Include the standard iostream header file.
- Include DelphiUnit.hpp (generated from your DelphiUnit.pas file when you built your Delphi package).
- Note: You must include iostream before you include DelphiUnit.hpp.
- In the main function, use
std::wcout << Delphiunit_Message << std::endl;
to print your Delphi resource string to the standard output. - Add
std::cin.get();
afterwards so that your console application does not exit execution until you press a key.
#pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <iostream>
#include <DelphiUnit.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
std::wcout << Delphiunit_Message << std::endl;
std::cin.get();
return 0;
}
Now you can run your C++ console application. A console should open and display your Delphi resource string:
- This is a Delphi resource string.
Uses
- System.ResourceString ( fr | de | ja )