如要保证调用托管dll,需定义好托管C++的头文件。
1.托管C++设置为混合编译模式。
2.头文件中要保证引入C++非托管库的头文件,如:
#include
#pragma comment( lib, "comsupp.lib" )
#pragma comment(lib, "comsuppw.lib")
#pragma comment(lib, "kernel32.lib")
#pragma pack(1)
#include
#include
using namespace std;
等,不可引入托管的命名空间,如
using system;
等。
3.在cpp文件中可引入托管库,如system等。
4.在头文件中需要定义类的成员变量时,可采用void *定义,
在cpp文件中,用到此指针时,reinterpret_cast*>(pYourPoint)
去转换指针。
5.在头文件中不要出现托管的数据类型。
按着以上原则,将此头文件以及托管dll,lib文件交给非托管C++工程,就可以使用了。
以下为网上所查得对应表:
1.托管C++设置为混合编译模式。
2.头文件中要保证引入C++非托管库的头文件,如:
#include
#pragma comment( lib, "comsupp.lib" )
#pragma comment(lib, "comsuppw.lib")
#pragma comment(lib, "kernel32.lib")
#pragma pack(1)
#include
#include
using namespace std;
等,不可引入托管的命名空间,如
using system;
等。
3.在cpp文件中可引入托管库,如system等。
4.在头文件中需要定义类的成员变量时,可采用void *定义,
在cpp文件中,用到此指针时,reinterpret_cast*>(pYourPoint)
去转换指针。
5.在头文件中不要出现托管的数据类型。
按着以上原则,将此头文件以及托管dll,lib文件交给非托管C++工程,就可以使用了。
以下为网上所查得对应表:
Win32 API | 非托管 C 语言类型 | 托管类名 | 说明 |
---|---|---|---|
handle | void* | System.IntPtr | 32位 |
byte | unsigned char | System.Byte | 8位 |
short | short | System.Int16 | 16位 |
word | unsigned char | System.UInt16 | 16位 |
int | int | System.UInt32 | 32位 |
uint | usigned int | System.UInt32 | 32位 |
long | long | System.UInt32 | 32位 |
bool | long | System.UInt32 | 32位 |
dword | unsigned long | System.UInt32 | 32位 |
ulong | unsigned long | System.UInt32 | 32位 |
char | unsigned long | System.Char | ANSI |
lpstr | char* | System.String或System.StringBuilder | ANSI |
lpcstr | const char* | System.String或System.StringBuilder | ANSI |
lpwstr | wchar_t* | System.String或System.StringBuilder | Unicode |
lpcwstr | const wchar_t* | System.String或System.StringBuilder | Unicode |
float | float | System.Single | 32位 |
double | double | System.Double | 64位 |