ResourceString (C++)

From Appmethod Code Examples
Jump to: navigation, search


This example shows how to load Object Pascal resource strings from a C++ application.

To build and test this example:

  1. Create a Object Pascal package where you can define a resource string:
    1. Create a new Object Pascal package, and save it as "DelphiPackage".
    2. Add a new Object Pascal unit to your package, and save this unit as "DelphiUnit".
  2. Create a C++ console application to load and show your Object Pascal resource string:
    1. On the Project Manager, right-click your project group and select Add New Project.
    2. On the New Items dialog box, select Appmethod C++ Projects on the tree view and, on the list of Appmethod C++ projects, select Console Application and click OK.
    3. On the New Console Application dialog box that opens, click OK to use the default C++ console application settings.
    4. Save your main C++ file as "main.cpp", your precompiled header file as "CppApplicationPCH.h", and your project as "CppApplication".
    5. Select Project > Options > C++ Linker and enable the "Link with the Object Pascal Runtime Library" option.


Add a "Message" resource string to the DelphiUnit.pas file:

unit DelphiUnit;


  Message = 'This is a Delphi resource string.';



Then right-click your DelphiPackage project on the Project Manager and select Build.

Add the generated Object Pascal package library file to your C++ console application:

  1. Right-click your CppApplication project on the Project Manager and select Add.
  2. 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\Studio\14.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:

  1. Include the standard iostream header file.
  2. Include DelphiUnit.hpp (generated from your DelphiUnit.pas file when you built your Object Pascal package).
    Note: You must include iostream before you include DelphiUnit.hpp.
  3. In the main function, use std::wcout << Delphiunit_Message << std::endl; to print your Object Pascal resource string to the standard output.
  4. 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>
  typedef char _TCHAR;
  #define _tmain main

#include <iostream>
#include <DelphiUnit.hpp>

 int _tmain(int argc, _TCHAR* argv[]) 
        std::wcout << Delphiunit_Message << std::endl;
        return 0;

Now you can run your C++ console application. A console should open and display your Object Pascal resource string:

This is a Object Pascal resource string.


See Also