我用VC调用dll时,遇到的几种方法都是在头文件中包含dll的.h文件或导入.tlb文件,请问有没有什么方法在不包含dll的.h或.tlb文件的情况下调用dll的方法?
解决方案 »
- 在vc2005中如何使用gdi+ ? 最好有个例子。
- active-x控件与com组件有什么区别吗?
- 不用MFC, 如何用Win32 API做一个状态条 status bar
- CEDIT如何做无边框窗口?
- COM中的QueryInerface函数中为何要使用一个指向指针的指针?
- 很简单,但是也很难,怎么回事啊???高手救命
- AnimateWindow的我问题(很菜问题)
- 如何用vc生成独立的exe文件?
- 怎样才能精通mfc?还有前途吗?
- 怎样才能把一个结构体通过Socket发出去,我试了强制转化成CString类型,可是不行.Help me!
- 请大家看看这是什么错???_高分有送!
- 大家都来看看是什么原因?聊天的小程序
// A simple program that uses LoadLibrary and
// GetProcAddress to access myPuts from MYPUTS.DLL.
#include <stdio.h>
#include <windows.h>
typedef VOID (*MYPROC)(LPTSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary("myputs");
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd) ("message via DLL function\n");
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("message via alternative method\n");
}
#include "stdafx.h"
#include "dll1.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported variable
DLL1_API int nDll1=1000;// This is an example of an exported function.
DLL1_API int MyPut(void)
{
return 42;
}// This is the constructor of a class that has been exported.
// see dll1.h for the class definition
CDll1::CDll1()
{
return;
}我这样调用的时候:
void CTestdllDlg::OnOK()
{
typedef VOID (*MYPROC)(LPTSTR);
// TODO: Add extra validation here
MYPROC ProcAdd;
char * FunName = "MyPut";
HINSTANCE dll_okno = LoadLibrary("dll1.dll");
if( dll_okno == NULL)
MessageBox("Load Dll Fail","Waring",MB_OK);
else
{
ProcAdd = (MYPROC) GetProcAddress(dll_okno, FunName);
if( ProcAdd != NULL)
{
MessageBox("OK", "Waring", MB_OK);
(ProcAdd);
}
else
MessageBox("No FUNCTION", MB_OK);
FreeLibrary(dll_okno);
}
}
为什么总是说找不到这个MyPut函数??
ProcAdd = (MYPROC) GetProcAddress(dll_okno, "MyPut");
或者
TCHAR * FunName = "MyPut";
是这个吗?我在exp文件中找到的