Translate a short (129 lines) Delphi DLL to a Visual Studio C++ Project. You find the Delphi DLL Source in the description.
## Deliverables
I tried to translate it on my own. Here is my C++ trial that does not work. Maybe you can use it as a starting point:
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
#include <[login to view URL]>
class DLLIMPORT DllClass
{
public:
DllClass();
virtual ~DllClass(void);
private:
};
class TMyClass;
struct TRegisterProcRec;
{
typedef int __fastcall (*TRegisterNamespace )( int , const String );
typedef int __fastcall (*TRegisterConstant )( int , const String , const Variant );
typedef int __fastcall (*TRegisterVariable )( int , const String , int , void* );
typedef int __fastcall (*TRegisterHeader )( int , const String , void* , int = 0, int = 0 );
typedef int __fastcall (*TRegisterProperty )( int , const String );
typedef int __fastcall (*TRegisterClassType )( int , TMetaClass* , bool = false );
typedef int __fastcall (*TRegisterClassReferenceType )( int , const String , const String );
typedef int __fastcall (*TRegisterClassTypeField )( int , const String );
typedef int __fastcall (*TRegisterRecordType )( int , const String , bool = false );
typedef int __fastcall (*TRegisterRecordTypeField )( int , const String );
typedef int __fastcall (*TRegisterVariantRecordTypeField )( int , const String , __int64 );
typedef int __fastcall (*TRegisterEnumType )( int , const String , int = 7 );
typedef int __fastcall (*TRegisterEnumValue )( int , const String , const int );
typedef int __fastcall (*TRegisterSubrangeType )( int , const String , int , int , int );
typedef int __fastcall (*TRegisterArrayType )( int , const String , int , int , bool = false );
typedef int __fastcall (*TRegisterDynamicArrayType )( int , const String , int );
typedef int __fastcall (*TRegisterPointerType )( int , const String , int );
typedef int __fastcall (*TRegisterSetType )( int , const String , int );
typedef int __fastcall (*TRegisterProceduralType )( int , const String , int );
typedef int __fastcall (*TRegisterEventType )( int , const String , int );
typedef int __fastcall (*TRegisterShortStringType )( int , const String , int );
typedef int __fastcall (*TRegisterInterfaceType )( int , const String , const TGUID , const String , const TGUID );
// TRegisterRTTIType = function(LevelId: Integer; pti: PTypeInfo): Integer;
typedef int __fastcall (*TRegisterTypeAlias )( int , const String , int );
struct TRegisterProcRec {
TRegisterNamespace RegisterNamespace;
TRegisterConstant RegisterConstant;
TRegisterVariable RegisterVariable;
TRegisterHeader RegisterHeader;
TRegisterProperty RegisterProperty;
TRegisterClassType RegisterClassType;
TRegisterClassTypeField RegisterClassTypeField;
TRegisterClassReferenceType RegisterClassReferenceType;
TRegisterRecordType RegisterRecordType;
TRegisterRecordTypeField RegisterRecordTypeField;
TRegisterVariantRecordTypeField RegisterVariantRecordTypeField;
TRegisterEnumType RegisterEnumType;
TRegisterEnumValue RegisterEnumValue;
TRegisterSubrangeType RegisterSubrangeType;
TRegisterArrayType RegisterArrayType;
TRegisterDynamicArrayType RegisterDynamicArrayType;
TRegisterPointerType RegisterPointerType;
TRegisterSetType RegisterSetType;
TRegisterProceduralType RegisterProceduralType;
TRegisterEventType RegisterEventType;
TRegisterShortStringType RegisterShortStringType;
TRegisterInterfaceType RegisterInterfaceType;
TRegisterTypeAlias RegisterTypeAlias;
};
typedef void __fastcall (*TRegisterDllProc )( const TRegisterProcRec& );
class TMyClass: public System::TObject {
public:
void __fastcall P( );
public: inline __fastcall TMyClass () {}
};
const int MyConst = 123;
int __fastcall MyFunc( int x, int y, int& MyConst )
{
int result = 0;
result = x + y;
return result;
}
void __fastcall TMyClass::TMyClass::P( )
{
writeln( 'P' );
}
void __fastcall RegisterDllProcs( const TRegisterProcRec& PaxRegisterProcs, int& MyConst )
{
int G = 0, H = 0;
{
H = [login to view URL]( 0, "u2" );
[login to view URL]( H, "MyConst", 123 );
G = [login to view URL]( H, __classid( TMyClass ) );
[login to view URL]( G, "procedure P;", &TMyClass::P());
[login to view URL]( G, "constructor Create;", __classid( new TMyClass ) );
[login to view URL]( H, "function MyFunc(X, Y: Integer): Integer;", &MyFunc( , MyConst) );
}
}
exports RegisterDllProcs;
}
#endif /* _DLL_H_ */