iCAx开思工具箱

标题: 调用MFC DLL出错? [打印本页]

作者: dreamerwj    时间: 2004-6-6 20:54
标题: 调用MFC DLL出错?
按清华书(UG/OPEN API)第16.3的例子,不过去掉了模态对话框部分,UgModalless文件能够成功生成,然而ugsample程序缺出现了如下错误:
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
nafxcw.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(timecore.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
Debug/ugsample.dll : fatal error LNK1120: 3 unresolved externals
本人VC水平有限,还望版主、zhjb113 及各路高手出手相助,感激不尽!
作者: dreamerwj    时间: 2004-6-7 10:15
大家帮帮我。。。。。
作者: zhjb113    时间: 2004-6-7 11:41
打开浏览器
访问google.com
输入:张军波 UG  
搜索相关网页
作者: dreamerwj    时间: 2004-6-7 14:39
张军波,你好,已经搜索了,但是那种方法生成的对话框是模态对话框,我现在想在UG环境中生成一个非模态对话框,听说清华书上那个例子是你的程序,一定要帮我呢。
     
作者: herolegend    时间: 2004-6-7 15:37
那本书的程序有问题!
那个程序里,无论是显示摸态对话框还是非摸态对话框,都是使用了一个MFC的全局函数AfxGetMainWnd()来获取主窗口指针,然后在创建对话框时,以这个主窗口指针作为对话框的父窗口。
显示摸态对话框的关键代码如下:
  CWnd *pParent=AfxGetMainWnd();
  DisplayModalDialog(pParent);
  
显示非摸态对话框的关键代码:
  CWnd *pParent=AfxGetMainWnd();
  DisplayModallessDialog(pParent);
  
如果在这两处的关键代码旁设断点调试,就可以观察到AfxGetMainWnd()返回的是NULL。  对话框固然是创建出来了,但是却没有了主窗口。
  我看过网上许多人都在如此引用,这么来做危险不危险姑且不论,这种做法肯定是不严谨的!
作者: dreamerwj    时间: 2004-6-7 17:01
问一下herolegend,有没有好的办法来生成非模态对话框。因为当在模态对话框中调用UG的对话框(比方就说点构造器),点构造器可以被激活,但是里面的按钮却不能够用(点击则会出现内存访问冲突的错误提示),此时只能够先关闭VC模态对话框,后面的对话框中按钮才能够用。
作者: kaka02    时间: 2004-6-9 03:59
把你的Email告诉我,我把我的代码部分传给你.
作者: dreamerwj    时间: 2004-6-9 08:03
zhouhaifeng_2001@hotmail.com,先谢过呢
作者: mizzle    时间: 2004-6-10 11:19
也给欧一个吧
mizzle0929@cjhy.com.cn
作者: haiying    时间: 2004-6-10 11:35
能不能发给我一份啊!
   ymhai@tom.com
多谢!
作者: zhjb113    时间: 2004-6-14 04:10
绝对可以创建非模态的对话框
作者: dreamerwj    时间: 2004-6-14 08:06
zhjb113,能不能给一个例子,大家已经等得很辛苦!
作者: dreamerwj    时间: 2004-6-14 08:15
我把模态对话框中的语句      
CMyDialog dlg;
dlg.DoModal();
替换为以下语句  
CMyDialog *dlg=new CMyDialog;
dlg->Create(IDD_DIALOG1,NULL);
dlg->ShowWindow(SW_SHOW);
为什么调用OPEN API的命令却不响应?
作者: zhjb113    时间: 2004-6-14 19:43
// blade.cpp : Defines the initialization routines for the DLL.
//
  
#include "stdafx.h"
#include "blade.h"
#include "bladenx.h"
#include "dlgbegin.h"
#include <uf_obj.h>
  
/////////////////////////////////////////////////////////////////////////////
// CBladeApp
  
BEGIN_MESSAGE_MAP(CBladeApp, CWinApp)
//{{AFX_MSG_MAP(CBladeApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
  
/////////////////////////////////////////////////////////////////////////////
// CBladeApp construction
  
CBladeApp::CBladeApp()
{
  // TODO: add construction code here,
  // Place all significant initialization in InitInstance
}
  
CBladeApp::~CBladeApp()
{
  // TODO: add construction code here,
    //结束UG
  UF_terminate();  
   
  
  // Place all significant initialization in InitInstance
}
  
/////////////////////////////////////////////////////////////////////////////
// The one and only CBladeApp object
  
CBladeApp theApp;
CDLGBegin *g_pDlgBegin=NULL ;
  
BOOL CBladeApp::InitInstance()  
{
  // TODO: Add your specialized code here and/or call the base class
  AfxEnableControlContainer(); //Add ActiveX control
  CoInitialize(NULL);//添加COM的调用
  
  return CWinApp::InitInstance();
}
       
  
static void do_ugopen_api(void)
{
  
  AFX_MANAGE_STATE(AfxGetStaticModuleState());
  
  CWnd* pWnd = AfxGetMainWnd();
  if(!g_pDlgBegin)
  {
    g_pDlgBegin=new CDLGBegin(pWnd);
    g_pDlgBegin->Create(IDD_DIALOGBEGIN);
  }
  g_pDlgBegin->ShowWindow(SW_SHOW);   
  
}
//这是UG的接口函数
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
  
  
  //这句话是显示对话框必需的
  AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
  /* Initialize the API environment */
  //初始化UG
    int errorCode = UF_initialize();
  if ( 0 == errorCode )
    {
    do_ugopen_api();
    }
  
}
  
int ufusr_ask_unload(void)
{     
  return (UF_UNLOAD_UG_TERMINATE);  
   
}
  
void ufusr_cleanup ()
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState());
  ::CoUninitialize();
  if(g_pDlgBegin)
  {
    g_pDlgBegin->DestroyWindow();
    delete g_pDlgBegin;
  }
}
作者: zhjb113    时间: 2004-6-14 19:48
这里给出了一个例子,是我以前的例子该过的,删除了无关的代码,可能会有错误
CDLGBegin是我定义的主对话框
  
请注意下面几个函数的写法
ufusr_ask_unload()  
ufusr_cleanup ()  
void do_ugopen_api()  
另外程序里面加入了对控件的支持
如果需要在对话框里面调用UG的对话框,请参考我以前在本站所发的帖子
作者: dreamerwj    时间: 2004-6-15 09:01
非常感谢zhjb113,已经可以实现!
作者: 深夜摔键盘    时间: 2004-6-15 17:26
static void do_ugopen_api(void)  
{  
  
  AFX_MANAGE_STATE(AfxGetStaticModuleState());  
   
  CWnd* pWnd = AfxGetMainWnd(); ///前辈能讲讲这个函数的作用吗?我测试时这个函数真的如herolegend所说的那样,是空值啊。
  
  if(!g_pDlgBegin)  
  {  
    g_pDlgBegin=new CDLGBegin(pWnd);  
    g_pDlgBegin->Create(IDD_DIALOGBEGIN);  
  }  
  g_pDlgBegin->ShowWindow(SW_SHOW);  
  
}
作者: zhjb113    时间: 2004-6-15 19:07
拜托,您查一下MSDN好吗
作者: 深夜摔键盘    时间: 2004-6-16 11:42
我早就查过啊。。。MSDN这么讲的
AfxGetMainWnd   
CWnd* AfxGetMainWnd( );
  
Return Value
  
If the server has an object that is in-place active inside a container, and this container is active, this function returns a pointer to the frame window object that contains the in-place active document.  
  
If there is no object that is in-place active within a container, or your application is not an OLE server, this function simply returns the m_pMainWnd of your application object.
  
If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.
  
Remarks
  
If your application is an OLE server, call this function to retrieve a pointer to the active main window of the application instead of directly referring to the m_pMainWnd member of the application object.
  
If your application is not an OLE server, then calling this function is equivalent to directly referring to the m_pMainWnd member of your application object.
  
这个函数在你的程序里使用的时候,应该返回UG的主窗口指针的,但是确实是NULL啊。
我想这个问题好久了,以前也发过贴,没人理,现在才知道一直流传的MFC调用是您的那个程序。多此一问,拜托老兄讲个透彻,好吗?
作者: zhjb113    时间: 2004-6-16 12:43
我没有跟踪过,因为MFC里面就是这么说的,况且程序运行也没有错误,所以,我以为肯定会返回UG的主窗口的。
不要管他返回值是什么,重点是把你的程序逻辑搞出来,不是吗?
  
If your application is not an OLE server, then calling this function is equivalent to directly referring to the m_pMainWnd member of your application object.  
  
I am sorry!
作者: xyy    时间: 2004-6-16 13:36
"我以为肯定会返回UG的主窗口的",可能是当前APPLICATION的窗口指针,是NULL,可能被UG保护了,不想给。
作者: 深夜摔键盘    时间: 2004-6-16 21:31

终于跟踪到了,的确返回了UG主窗口,返回结果和我用SPY++所查的结果是一致的,谢谢zhjb!!!
我重新写了一个对话框,我觉得清华教程里的那个程序有点牵强附会了。
作者: mazhiguo    时间: 2006-3-23 18:39
herolegend说得非常对,我也是对此深表怀疑!
作者: mazhiguo    时间: 2006-3-24 09:47
标题: 回复7楼的帖子!
mazhiguo01@163.com拜读您的代码!望给予




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3