How to get the pointer to MFC document class in a single SDI MFC app built as DLL, export.cpp setup standard call to function?

huangapple go评论92阅读模式
英文:

How to get the pointer to MFC document class in a single SDI MFC app built as DLL, export.cpp setup standard call to function?

问题

我有一个在VS2005中创建的MFC程序,它是一个动态链接库,采用单文档界面(SDI)模式,应用程序名称为c2view,文档类为c2viewDoc,视图类为c2viewView。这是一个由4个组件构成的模型,采用单文档界面。

在动态链接库中有一个函数,在export.h和export.cpp中定义为标准调用(a,b)。我可以访问主窗口指针;

但是,我需要指向文档类Cc2viewDoc的指针,以便我可以使用调用参数a和b来更新文档类中的成员变量!Jeff Prosise的第503页暗示m_pDocument是Cc2viewView类的成员变量,所以我想,如果你能给我Cc2viewView类的指针,cvwcp*,我可以尝试继续使用cvwcp->m_pDocument。

经过数周的努力,我成功使MFC c2view.dll从C#中调用并进行绘图。现在的下一步是将调用参数Shograph的int a和int b传递给Cc2viewDoc的成员以进行更新。

请帮助我。

我尝试从C Win App或c2viewApp中获取C文档类的指针,如AfxGetApp(),但都没有成功。
我在export.cpp中:

Int_stdcall Shograph(a, b)

并且需要文档类的指针,以便我可以基于a和b更新它的成员。

英文:

I have an MFC program in VS2005 dynamic link library, single SDI, app name c2view, document class c2viewDoc, view class c2viewView. This is a 4 component model, single doc interface.

Inside the dynamic link library is a function defined in export h and export.cpp as stand call ( a , b) I do have access to the main window pointer;

But, I need the pointer to the document class Cc2viewDoc, so that I can use the calling parameters a and b to update member variables in the document class !!
Page 503 of Jeff Prosise imples that m_pDocument is a member variable of the Cc2viewView class, so, I suppose, if you can get me the pointer to the Cc2viewView class, cvwcp*, I could try to proceed with cvwcp->m_pDocument.

After many weeks of struggle I did get the MFC c2view.dll to call from c# and do a drawing. Now the next step is to pass the called parameters on the argument list of Shograph int a and int b to update members in the Cc2viewDoc.

Please help me.

I tried to get the pointer to the C Document class from C Win App or c2viewApp as A f x g e t A p p ( )

nothing works.
I am in export.cpp

  • I n t _ s t d call s h o g r a p h ( a , b)
    and need the pointer to the doc class so I can update its members based on a and b

答案1

得分: 2

你不应该将你的DLL的内部细节暴露给外部世界,有很多原因。

首要原因 - 没有人应该关心你的DLL是否实现了MFC文档/视图架构。同样重要的是 - 这不是安全的,因为存在版本冲突、对象生命周期管理等潜在问题。

我认为最佳实践是为你所需的功能创建一个简单的“extern C” API,并从任何客户端调用它。

英文:

You should not expose internals of your DLL to the outside world, for many reasons.

Primarily - no one should care if your DLL implements MFC Document/View architecture. As important - it is simply not safe, as there is potential for a version conflict, object lifetime management, etc.

The best practice, I believe, is to create a simple "extern C" API for your required functionality and call it from whwtever client you have.

huangapple
  • 本文由 发表于 2023年7月28日 03:25:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定