游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1276|回复: 0

LoadLibrary cand call MFC DLL's fucntion

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2009-2-19 13:56:00 | 显示全部楼层 |阅读模式
I meet a problem when I call the another MFC DLL's function.

I create two projects.

First project is called maxProjectMFCDLL, which is a MFC DLL project.

maxProjectMFCDLL.def's content as below:

LIBRARY      "maxProjectMFCDLL"

EXPORTS
    fDoExport @1


maxProjectMFCDLL.cpp's additional content as below:
int fDoExport(int a)
{
        MessageBox(NULL,"name","Warn",MB_OK);
        return TRUE;
}

Second project is called TestDialog, which is a MFC Dialog project.
I add a button to the dialog and add the function OnBnClickedButton1 for clicking the button.

void CTestDialogDlg::OnBnClickedButton1()
{
        typedef int (CALLBACK* D_MYEXPORT)(int);

        HMODULE l_mod;
        D_MYEXPORT l_export=NULL;
        int l_ret=0;

        l_mod=LoadLibrary(L"..\\maxProjectMFCDLL.dll");

        if (l_mod!=NULL)
        {
                int a=1;
                l_export=(D_MYEXPORT)GetProcAddress(l_mod,"fDoExport");
                l_ret=l_export(a);
                FreeLibrary(l_mod);
        }
}

After I build the Frist and Second projects, run the Second project. VC++ appear a error message(http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/MFC%20DLL.JPG).
The message is "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one callinc convention with a function pointer declared with a different calling convention."

Could somebody tell me how to solve this problem?

I put my complete source code at http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/3ds%20max%20Plugin%20Two%20Project%20Q2.rar
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 06:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表