16,548
社区成员




扩展dll代码:
extern "C" int fun();
extern "C" int fun()
{
return 11110;
}
测试工程代码:
//main.c
#include<windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <Shlwapi.h>
#include <string.h>
#include <assert.h>
int main()
{
HINSTANCE hInst=NULL;
int testVal=-1;
CHAR strModuleFileName[MAX_PATH]={0};
CHAR strDllName[MAX_PATH]="test9.dll";
CHAR strDllComName[MAX_PATH]={0};
char* pstr=NULL;
typedef int(* pFun)();
pFun myfun;
GetModuleFileName(GetModuleHandle(NULL),strModuleFileName,MAX_PATH);
pstr=strrchr(strModuleFileName,'\\');
assert(pstr);
*pstr='\0';
PathCombine(strDllComName,strModuleFileName,strDllName);
hInst=LoadLibrary(strDllComName);
if(!hInst)
{
printf("加载dll失败,错误码为:%d\r\n",GetLastError());
return 0;
}
myfun=(pFun)GetProcAddress(hInst,"fun");
testVal=myfun();
printf("%d",testVal);
return 0;
}
自己验证吧, 无论扩展还是规则dll,均可以调用。