0

我真的需要你的帮助,因为我在将一个 .DLL 函数集成到我的控制台应用程序中时遇到了很多问题。这个 .DLL 包括获取 2 个字符(字符 a 和字符 b)(输入)并将它们添加到一个字符中。例如: Char A=H Char B=I Output=HI 但这是问题所在。当我编译控制台应用程序并运行它时,它说没有检测到该函数。这是我的问题..为什么地狱没有即使在 .def 文件中我列出了 LIBRARY 和唯一导出的函数,它也能找到函数吗?请帮助我。 这是 .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.**
4

1 回答 1

0

Ok, I looked at what you have above and wondered where in your code you import the dll. I'm kind of new at this myself, so I found this article on how to do it.

If I understand correctly, in your console application you need to have a line like (assuming the name of your dll is "your.dll":

[DllImport("your.Dll")]

by the way, welcome to Stack Overflow, I noticed it is your first day! CHEERS!

于 2013-01-23T07:53:36.137 回答