简体   繁体   中英

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

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 */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM