开发者

Importing a DllMain winapi .dll into Visual Studio project C++

开发者 https://www.devze.com 2022-12-26 05:34 出处:网络
I have the .def file, .lib file, the .dll, the source files. It\'s using WINAPI DllMain, all its functions follow that.

I have the .def file, .lib file, the .dll, the source files.

It's using WINAPI DllMain, all its functions follow that.

It's like this:

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
       )
{
    return TRUE;
}


extern "C"
{
int WINAPI DoSomething() { return -1; }开发者_开发技巧
int WINAPI DOSOMETHIGNELSE!() { return 202020; }
};

IN the project settings linker I added the .lib file. There is no header file for the actual functions in the extern "C" part.

I include windows.h try to call DoSomething() but doesnt know what it is.


I'm not sure exactly what you're asking for, but I think at the least you'll need to create a .h file for client code to include so it can call functions in the the DLL - otherwise how will the compiler know what the name DoSomething is?

The header file should probably look something like:

#ifndef DOSOMETHING_H
#define DOSOMETHING_H

#ifdef __cplusplus
extern "C"
{
#endif

int WINAPI DoSomething(void);


// I commented out the 2nd function because I don't think the `!` character 
//  could ever be valid there

//int WINAPI DOSOMETHIGNELSE!();


#ifdef __cplusplus
}
#endif

#endif /* DOSOMETHING_H */
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号