如何调用这个DLL文件

妖怪 2004-07-29 08:47:14
我写了个DLL文件,其中有个函数是
STDMETHODIMP MYServer::StartServer(int *RetVal)
{
if (SHAREDServer.StartServer())
*RetVal = 1;
else
*RetVal = 0;
return S_OK;
}
不知道如何在其他的工程中调用,最好有源代码,LoadLibrary和FreeLibrary
的操作我会,主要是中间的获得指针的函数。
...全文
123 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_dan 2004-08-04
  • 打赏
  • 举报
回复
通过AFX_EXT_CLASS 进行声明调用
然后再使用EXTERN‘C’ 来用纯C做
妖怪 2004-07-29
  • 打赏
  • 举报
回复
我也知道这段程序,可惜现在的程序涉及了类的操作
cgipro 2004-07-29
  • 打赏
  • 举报
回复
一个例子,供参考
//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;
}
妖怪 2004-07-29
  • 打赏
  • 举报
回复
我不能修改源程序和DLL文件
妖怪 2004-07-29
  • 打赏
  • 举报
回复
如何将整个类输出
whale 2004-07-29
  • 打赏
  • 举报
回复
因为你使用了类,最好是将整个类输出,否则别的程序不好调用,因为member function的参数里面有一个隐含的this指针。要输出类使用AFX_EXT_CLASS宏。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧