刚开始接触 VC++/CLI 这种语言,遇到很多问题,希望大家能给与帮助,先谢谢了!开发环境:VS2010 VC++/CLI OS:Windows7 .NetVersion:4.0我的程序是这样的,先按通常方法创建了一个名为VC_KTKGK的VC项目,然后在项目里添加了一个VCTest.h的头文件,在这个头文件里声明了一些构造体变量和DLL链接函数,然后我在程序启动的VC_KTKGK.cpp的文件里添加了读入VCTest.h的语句。然后我在Form1里添加了按钮,在按钮的点击事件里使用VCTest.h文件里声明的链接函数和构造体变量,一切都很正常。然后我在项目里添加了Form2,当我想在Form2里像Form1那样,访问VCTest.h文件里声明的构造体变量时,却发生了变量未定义的错误。 我想知道该怎样做才能在Form2里也能正常访问 VCTest.h文件里声明的变量。 还有,程序执行时,Form2窗体是用Form1的按钮事来打开的,有没有什么需要特别注意的地方。程序代码如下://******* VCTest.h ********************using namespace System::Runtime::InteropServices;#ifndef _VCTest_H_
#define _VCTest_H_
#define X1OFFSET (0x00)
#define X2OFFSET (0x30) typedef struct {
long I_ope;
long I_sts;
} GET_OPERATION;typedef struct {
long V_pls;
long V_slp;
long V_ppo;
} SET_POSITIONAL;typedef struct {
unsigned long V_port;
long V_pl;
long V_bkrsh;
long V_bktmp;
} DLL_OPERATION;typedef struct {
SET_POSITIONAL
SET;
GET_OPERATION GET;
DLL_OPERATION DLL;
} AX_AP;AX_AP AA;
AX_AP BB;[DllImport("asXXX.dll")]
extern void AxReSet(AX_AP *p);
[DllImport("asXXX.dll")]
extern void AxInitReSet(AX_AP *p);
#endif//*************************************//********* VC_KTKGK.cpp ****************
#include "stdafx.h"
#include "VCTest.h"
#include "Form1.h"using namespace VC_KTKGK;[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
//Windows XP 效果
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); // 主窗体做成
Application::Run(gcnew Form1());
return 0;
}//*************************************//******* Form1.h 按钮事件 **************private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
AxInitReSet(&AA);
}
//*************************************//******* Form2.h 按钮事件 **************private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
AxInitReSet(&BB); // ****** 这一句在编译时出错, 提示 BB变量未定义 ******
}
//*************************************在Form2的按钮点击事件里,不能访问 VCTest 里声明的变量。 想知道怎么办才可以访问。
#define _VCTest_H_
#define X1OFFSET (0x00)
#define X2OFFSET (0x30) typedef struct {
long I_ope;
long I_sts;
} GET_OPERATION;typedef struct {
long V_pls;
long V_slp;
long V_ppo;
} SET_POSITIONAL;typedef struct {
unsigned long V_port;
long V_pl;
long V_bkrsh;
long V_bktmp;
} DLL_OPERATION;typedef struct {
SET_POSITIONAL
SET;
GET_OPERATION GET;
DLL_OPERATION DLL;
} AX_AP;AX_AP AA;
AX_AP BB;[DllImport("asXXX.dll")]
extern void AxReSet(AX_AP *p);
[DllImport("asXXX.dll")]
extern void AxInitReSet(AX_AP *p);
#endif//*************************************//********* VC_KTKGK.cpp ****************
#include "stdafx.h"
#include "VCTest.h"
#include "Form1.h"using namespace VC_KTKGK;[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
//Windows XP 效果
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); // 主窗体做成
Application::Run(gcnew Form1());
return 0;
}//*************************************//******* Form1.h 按钮事件 **************private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
AxInitReSet(&AA);
}
//*************************************//******* Form2.h 按钮事件 **************private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
AxInitReSet(&BB); // ****** 这一句在编译时出错, 提示 BB变量未定义 ******
}
//*************************************在Form2的按钮点击事件里,不能访问 VCTest 里声明的变量。 想知道怎么办才可以访问。
解决方案 »
- Microsoft Visual Studio LightSwitch 2011抢先看
- 协议转化
- 如何根据指定的路径读取文件或输出文件?
- 程序在盘符下目录不能运行???
- 百分悬赏,谁知道如何对VSS 6.0进行扩展编程
- 感觉按照这种趋势下去,VC会逐渐退出历史舞台,是这样子吗?
- 新手关于CString的问题
- 在VC.net中如何给菜单添加快捷键?
- POSTMESSAGE 和 SENDMESSAGE 有什么不同呀?
- 在一个函数中使用GetSafeHandle()保存CPen对象的句柄,在另一个函数中使用CPen::FromHandle()获得句柄,为什么句柄值是不同的,使用的类
- 窗口置顶 后全屏 如何取消置顶属性?
- VC++/CLI 关于不同窗体访问相同变量的问题
我是本版版主
此帖已多日无人关注
请您及时结帖
如您认为问题没有解决可按无满意结帖处理
另外本版设置了疑难问题汇总帖
并已在版面置顶
相关规定其帖子中有说明
您可以根据规定提交您帖子的链接
如您目前不想结帖只需回帖说明
我们会删除此结帖通知见此回复三日内无回应
我们将强制结帖
相关规定详见界面界面版关于版主结帖工作的具体办法