我真的需要你的帮助,因为我在将一个.DLL函数集成到我的控制台应用程序中时遇到了很多问题。这个.DLL包含获取2个字符(Char a和Char b) (输入)并将它们添加到一个字符中。例如: 字符A = H 字符B = I 输出= HI 但问题出在这里。当我编译控制台应用程序并运行它时,它说函数没有被检测到。这里是我的问题。为什么地狱不找到函数,即使在.def文件中我已经列出了LIBRARY和唯一的导出函数?请帮助我。 这是.DLL SOURCE无法通过控制台应用程序调用.DLL函数
#include "stdafx.h"
char concatenazione(char a,char b)
{
return a+b;
}
**THIS IS THE .DEF FILE OF THE .DLL**
LIBRARY Concatenazione
EXPORTS
concatenazione @1
**And this is the dllmain.cpp**
#include "stdafx.h"
BOOL APIENTRY DllMain(HMODULE 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 the Console Application partial source(For now it just includes the functions import part)**
#include <iostream>
#include <windows.h>
#include <stdio.h>
typedef int (__cdecl *MYPROC)(LPWSTR);
int main(void)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("C:\\ConcatenazioneDiAyoub.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "concatenazione");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
return 0;
}
**The Console Applications runs fine but the output is "Message printed from executable".This means that the function hasn't been detected.**
我会告诉你[阅读此](http://msdn.microsoft.com/en-us/library/z4zxe9k8(v = vs.80).aspx),然后在你的代码中加入更好的错误处理和报告,以确定是加载DLL失败还是找不到发生的proc失败 – WhozCraig
你可能想将DLL的路径添加到PATH环境变量PRI或运行到尝试使用DLL的应用程序。 – alk
现在它不会给我那个消息 – NTAuthority