vs2008里,创建c++.net的项目,怎么引用自己的类库呢
用vs2008新建立了一个Solution2的解决方案,新建完这后,添加一个windows窗体应用程序(c++的)Test1如图:
这后在添加一个名字为LR500的类库(也是c++的),如图:
在默认生成的文件LR500.h中的加入如下代码:
- C/C++ code
// LR500.h#pragma once#ifndef LR500#define LR500using namespace System;namespace LR500 { public ref class Class1 { // TODO: 在此处添加此类的方法。 public: Class1(); Class1(int index); private: int _index; };}#endif
在LR500.cpp文件里加入如下代码:
- C/C++ code
// 这是主 DLL 文件。#include "stdafx.h"#include "LR500.h"LR500::Class1::Class1(){ this->_index = 0;}LR500::Class1::Class1(int index){ this->_index = index;}
之后我在Test1项目里添加对LR500类库的引用,在Form1的Load事件里加入如下代码:
- C/C++ code
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { LR500::Class1 cls1(2); }
编译程序通不过,但是我把LR500.h中的
- C/C++ code
[color=#FF0000]#ifndef LR500#define LR500...#endif[/color]
去掉,就能运行成功,有谁知道为什么吗?
[解决办法]
Visual C++ 2008入门经典(中文版).pdf
[解决办法]
你建的工程不是C++的、
[解决办法]