我真的需要你的幫助,因爲我在將一個.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