woka

对话框中获得文档指针pDoc

For   a   single   document   interface   (SDI)   application,   add   the   following   code   to   your   SDI   document's   implementation   file   for   CMyDoc::GetDoc():    
   
        //   SDI   document   implementation   file  
        CMyDoc   *   CMyDoc::GetDoc()  
        {  
              CFrameWnd   *   pFrame   =   (CFrameWnd   *)(AfxGetApp()->m_pMainWnd);  
              return   (CMyDoc   *)   pFrame->GetActiveDocument();
 
        }  
   
   
  For   a   multiple   document   interface   (MDI)   application,   the   CMyDoc::GetDoc()   code   should   be   the   following:    
   
        CMyDoc   *   CMyDoc::GetDoc()  
        {  
              CMDIChildWnd   *   pChild   =  
                      ((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();  
   
              if   (   !pChild   )  
                      return   NULL;  
   
              CDocument   *   pDoc   =   pChild->GetActiveDocument();  
   
              if   (   !pDoc   )  
                    return   NULL;  
   
              //   Fail   if   doc   is   of   wrong   kind  
              if   (   !   pDoc->IsKindOf(   RUNTIME_CLASS(CMyDoc)   )   )  
                    return   NULL;  
   
              return   (CMyDoc   *)   pDoc;
 
        }  

posted @ 2009-05-17 20:07 woka 阅读(776) | 评论 (0)编辑 收藏

C2059 Error Using extern "C" in .C Source Files

The information to this article applies to:
The Microsoft C/C++ Compiler included with: - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0,

     4.1, 5.0

SUMMARY
Use of "extern "C"" in source files that have a .C extension causes error C2059, and results in this error message:

   error C2059:syntax error:'string'

CAUSE
In the C language, the string-literal "C" is not recognized. It is used in C++ to prevent name decoration.

RESOLUTION
Remove the string-literal "C" in extern declarations, or use the following in the function declaration:


   #ifdef __cplusplus
      extern "C"
   #endif 

http://blog.csdn.net/cxyol/archive/2006/10/20/1342650.aspx

posted @ 2009-04-28 21:29 woka 阅读(1083) | 评论 (0)编辑 收藏

error LNK2019 无法解析的外部符号

无法解析的外部符号“symbol”,该符号在函数“function”中被引用

在 function 中找到了未定义的外部符号 (symbol)。若要解决此错误,请提供符号定义或移除引用它的代码。

在 Visual C++ .NET 2003 中,如果使用了 /clr 而未将 CRT 链接到可执行文件,将生成此错误。任何由编译器在未使用 /clr:initialAppDomain 时生成的对象代码都包含对 _check_commonlanguageruntime_version 函数的引用,该函数在 C 运行时库 (CRT) 中定义。如果应用程序在运行库的版本 1 上运行,该函数将会生成一个错误信息。当前编译器生成的代码与运行库的版本 1 不兼容。因此,如果在 Visual C++ .NET 2003 中编译时不使用 CRT,则应在代码中包含 _check_commonlanguageruntime_version 函数的定义。作为使用 _check_commonlanguageruntime_version 函数的替代方法,您可以与 nochkclr.obj 链接。nochkclr.obj 包含该函数的一个空版本,当您在运行库的版本 1 上运行应用程序时,nochkclr.obj 不生成错误信息。若要使用当前编译器版本生成应用程序以在运行库的以前版本上运行,应使用 /clr:InitialAppDomain。

若要生成一个纯 MSIL 可执行文件(不与 CRT 链接),则必须在项目中定义该函数,而不能使用 nochkclr.obj(.obj 是本机代码)。有关可验证代码的更多信息,请参见产生可验证的 C++ 托管扩展组件。有关从托管 C++ 项目创建纯 MSIL 输出文件的更多信息,请参见将 C++ 托管扩展项目从混合模式转换成纯 IL。

本主题的其余部分讨论 LNK2019 的其他原因。

请看下面的示例:

extern int i;
extern void g();
void f()
{
i++;
g();
}
int main()
{
}
如果在生成中包含的某个文件中没有定义 i 和 g,链接器将生成 LNK2019。可以添加这些定义,方法是将包含这些定义的源代码文件包括为编译的一部分。或者可以将包含这些定义的 .obj 或 .lib 文件传递给链接器。

对于从早期版本升级到当前版本的 C++ 项目,如果定义了 __UNICODE 并且入口点为 WinMain,需要将入口点函数的名称更改为 _tWinMain 或 _tmain。

导致 LNK2019 的常见问题有:

符号声明包含拼写错误,以致于符号声明与符号定义不同。
使用了一个函数,但其参数的类型或数量与函数定义不匹配。
函数声明使用和函数定义使用中的调用约定(__cdecl、__stdcall 或 __fastcall)不同。
符号定义在编译为 C 程序的文件中,而符号是在 C++ 文件中不带 extern "C" 修饰符声明的。在此情况下,请修改声明,例如不是使用:
extern int i;
extern void g();
而使用:

extern "C" int i;
extern "C" void g();
同样,如果在将由 C 程序使用的 C++ 文件中定义符号,请在定义中使用 extern "C"。

符号定义为静态,但稍后在文件外部被引用。
没有定义静态类成员。例如,应单独定义下面类声明中的成员变量 si:
#include <stdio.h>
struct X {
static int si;
};

// int X::si = 0; // uncomment this line to resolve

void main()
{
X *px = new X[2];
printf("\n%d",px[0].si); // LNK2019
}
也可能由于为 Visual Studio .NET 2003 进行的一致性工作生成此错误:模板友元和专用化。在 Visual Studio .NET 2003 中,必须定义声明新的非模板函数的友元声明。

要使代码在 Visual C++ 的 Visual Studio .NET 2003 和 Visual Studio .NET 版本中均有效,请显式指定友元函数的模板参数列表。

// LNK2019.cpp
// LNK2019 expected
template<class T>
void f(T)
{
}

template<class T>
struct S
{
friend void f(T);
// Try the folowing line instead:
// friend void f<T>(T);
};

int main()
{
S<int> s;
f(1); // unresolved external
}
/VERBOSE 链接器选项帮助您查看链接器引用的文件。DUMPBIN 实用工具的 /EXPORT 和 /SYMBOLS 选项还可以帮助您查看 dll 和对象/库文件中定义的符号。
http://zhidao.baidu.com/question/20263216.html

posted @ 2009-04-28 21:16 woka 阅读(16983) | 评论 (1)编辑 收藏

仅列出标题
共2页: 1 2 
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜