我错在哪? 如果使用隐含调用,把lib和dll放在程序目录,把lib文件加入工程,编译即可。如果使用显式调用,要使用LoadLibrary. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 显式调用的例子:工程mydll(win32应用):mydll.def:LIBRARY "mydll"EXPORTS donothingmydll.cpp:#include"windows.h" int donothing(void)//_declspec(dllexport){ MessageBox(NULL, "断点:donothing", "TestDll", MB_OK); return 1;}工程testdll(win32应用):testdll.cpp:#include"windows.h"//int donothing(char addordel,char filename);int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ HMODULE hMyDll; int (* pMyFun)(void); int bReturn; MessageBox(hInstance, "断点:1", "TestDll", MB_OK); hMyDll=LoadLibrary("mydll.dll"); MessageBox(hInstance, "断点:2", "TestDll", MB_OK); pMyFun=(int(*)(void))GetProcAddress(hMyDll,"donothing"); if(pMyFun) MessageBox(hInstance, "断点:3", "TestDll", MB_OK); bReturn=(*pMyFun)(); MessageBox(hInstance, "断点:4", "TestDll", MB_OK); FreeLibrary(hMyDll); return 1;}两个工程三个文件,把第一个工程的DLL文件放到第二个工程的目录里。这是我学习dll是写的练习。 显式调用的例子:win32应用DLL:file mydll.cpp#include"windows.h"int donothing(void){ MessageBox(NULL,"断点:donothing","TestDll",MB_OK); return 1;}file mydll.defLIBRARY "mydll"EXPORTS donothing调用DLL:file testdll.cpp#include"windows.h"int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ HMODULE hMyDll; int (* pMyFun)(void); int bReturn; hMyDll=LoadLibrary("mydll.dll"); pMyFun=(int(*)(void))GetProcAddress(hMyDll,"donothing"); bReturn=(*pMyFun)(); FreeLibrary(hMyDll); return 1;}把第一个工程输出的DLL放到第二个工程的目录里。 选中VC菜单Project下的Setting项,在link属性页中的Object/library modules下加上你的lib文件名,即可。 选取菜单Project-->Setting,中的link属性页,在Object/library modules项添加自己的lib文件即可。 如何将PropertySheet下面的按钮功能添加到菜单栏(无论什么方法) IOCP新手问题,请高人指点,谢谢,在线等.... 简单问题 马上给分 有关16位系统和32位系统的问题 使用自绘的按钮,怎样给他添加位图 MFC工程想要抓获其他应用程序发送的数据,怎么弄? Visual stadio中compile一个文件时候为什么出错? 关于滚动视图的问题? 用vc6编译程序时跳出系统属性对话框?在线等 我想考程序员,有几个问题 怎样去掉CPropertySheet中的应用按钮? 大虾们好:怎样在WINDOWS NT下编程关机?
EXPORTS
donothingmydll.cpp:#include"windows.h" int donothing(void)//_declspec(dllexport)
{
MessageBox(NULL,
"断点:donothing",
"TestDll",
MB_OK); return 1;
}工程testdll(win32应用):testdll.cpp:#include"windows.h"//int donothing(char addordel,char filename);
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
HMODULE hMyDll;
int (* pMyFun)(void);
int bReturn; MessageBox(hInstance,
"断点:1",
"TestDll",
MB_OK);
hMyDll=LoadLibrary("mydll.dll"); MessageBox(hInstance,
"断点:2",
"TestDll",
MB_OK);
pMyFun=(int(*)(void))GetProcAddress(hMyDll,"donothing");
if(pMyFun)
MessageBox(hInstance,
"断点:3",
"TestDll",
MB_OK);
bReturn=(*pMyFun)(); MessageBox(hInstance,
"断点:4",
"TestDll",
MB_OK); FreeLibrary(hMyDll); return 1;
}两个工程三个文件,把第一个工程的DLL文件放到第二个工程的目录里。
这是我学习dll是写的练习。
win32应用
DLL:
file mydll.cpp
#include"windows.h"int donothing(void)
{
MessageBox(NULL,"断点:donothing","TestDll",MB_OK);
return 1;
}file mydll.def
LIBRARY "mydll"
EXPORTS
donothing调用DLL:
file testdll.cpp
#include"windows.h"
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
HMODULE hMyDll;
int (* pMyFun)(void);
int bReturn; hMyDll=LoadLibrary("mydll.dll"); pMyFun=(int(*)(void))GetProcAddress(hMyDll,"donothing");
bReturn=(*pMyFun)(); FreeLibrary(hMyDll); return 1;
}把第一个工程输出的DLL放到第二个工程的目录里。