0

1 つの .DLL 関数をコンソール アプリケーションに統合する際に多くの問題を抱えているため、本当に助けが必要です。 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

わかりました、私はあなたが上に持っているものを見て、あなたのコードのどこにdllをインポートするのか疑問に思いました. 私はこれに慣れていないので、その方法についてこの記事を見つけました。

私の理解が正しければ、コンソール アプリケーションに次のような行が必要です (dll の名前が「your.dll」であると仮定します)。

[DllImport("your.Dll")]

ところで、Stack Overflow へようこそ。今日があなたの初日であることに気付きました。乾杯!

于 2013-01-23T07:53:36.137 に答える