我写了个DLL文件,其中有个函数是
STDMETHODIMP MYServer::StartServer(int *RetVal)
{
if (SHAREDServer.StartServer())
*RetVal = 1;
else
*RetVal = 0;
return S_OK;
}
不知道如何在其他的工程中调用,最好有源代码,LoadLibrary和FreeLibrary
的操作我会,主要是中间的获得指针的函数。
STDMETHODIMP MYServer::StartServer(int *RetVal)
{
if (SHAREDServer.StartServer())
*RetVal = 1;
else
*RetVal = 0;
return S_OK;
}
不知道如何在其他的工程中调用,最好有源代码,LoadLibrary和FreeLibrary
的操作我会,主要是中间的获得指针的函数。
//testDll.cpp
#include "stdio.h"
#include "windows.h"
//#include "testDll.h"
void main()
{
//本来定义的格式为:typedef int (* pMax)(int a,int b);
//编译没有问题,但是执行总会出错,改成下面的形式,问题解决
typedef int (__stdcall * pMax)(int,int);
typedef int (__stdcall * pMin)(int,int);
HINSTANCE hLibrary;
hLibrary=LoadLibrary("dlltest.dll");
pMax nMax;
nMax=(pMax)GetProcAddress(hLibrary,"nMax");
int max=nMax(66,130);
printf("%d\n",max);
FreeLibrary(hLibrary);
}下面是DLL的source code
// dlltest.cpp : Defines the entry point for the DLL application.
//
#include "dlltest.h"
#include "stdafx.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;}
int WINAPI nMax(int a, int b)
{
if(a>=b)return a;
else
return b;
}
int WINAPI nMin(int a, int b)
{
if(a>=b)return b;
else
return a;
}
然后再使用EXTERN‘C’ 来用纯C做