| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1453 人关注过本帖
标题:关于动态链接库的问题
取消只看楼主 加入收藏
*明华锐达*
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-2-7
收藏
 问题点数:0 回复次数:0 
关于动态链接库的问题

我昭了个例子写的一个动态链接库,为什么会出现这问题,而他的可以编译,???
代码如下:
// dllDemo.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "dllDemo.h"
#include <stdio.h>
HMODULE g_hModule;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hMoudle=(HMODULE)hModule;
break;

}
return TRUE;// 09DllDemo.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "dllDemo.h"
#include <stdio.h>

HMODULE g_hModule;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hModule = (HMODULE)hModule; // 保存模块句柄
break;
}
return TRUE;
}

// 自定义导出函数
void ExportFunc(LPCTSTR pszContent)
{
char sz[MAX_PATH];
::GetModuleFileName(g_hModule, sz, MAX_PATH);
::MessageBox(NULL, pszContent, strrchr(sz, '\\') + 1, MB_OK);
}

}

DLLDEMO_API void ExportFun(LPCTSTR pszContent)
{
char sz[Max_PATH];
GetModuleFileName(g_hMoudle,sz,MAX_PATH);
MessageBox(NULL,pszContent,strrchr(sz,'\\')+1,MB_OK);
}

编译后问题如下:
--------------------Configuration: dllDemo - Win32 Debug--------------------
Compiling...
dllDemo.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(16) : error C2065: 'g_hMoudle' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(16) : error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\program files\microsoft visual studio\myprojects\dlldemo\dlldemo.h(17) : error C2599: 'CDllDemo::CDllDemo' : local class member functions must be defined within the class
c:\program files\microsoft visual studio\myprojects\dlldemo\dlldemo.h(17) : see declaration of 'CDllDemo::CDllDemo'
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(33) : error C2601: 'DllMain' : local function definitions are illegal
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(45) : error C2601: 'ExportFunc' : local function definitions are illegal
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2065: 'Max_PATH' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2057: expected constant expression
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2466: cannot allocate an array of constant size 0
C:\Program Files\Microsoft Visual Studio\MyProjects\dllDemo\dllDemo.cpp(59) : error C2133: 'sz' : unknown size
Error executing cl.exe.
Creating browse info file...

dllDemo.dll - 9 error(s), 0 warning(s)

搜索更多相关主题的帖子: 动态链接库 include reason quot call 
2007-04-28 10:31
快速回复:关于动态链接库的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013650 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved