C++ 图形用户界面 - 'Marshal' : is not a class or namespace name

标签 c++ user-interface marshalling

非常感谢任何帮助。感谢您抽出时间审阅我的问题。

我目前收到错误消息

 1>c:\users\fordn_000\documents\tcc_odu\it310\programs\it310_homework_program_2_nford\it310_homework_program_2_nford\Form1.h(625): error C2653: 'Marshal' : is not a class or namespace name
 1>c:\users\fordn_000\documents\tcc_odu\it 310\programs\it310_homework_program_2_nford\it310_homework_program_2_nford\Form1.h(625): error C3861: 'StringToHGlobalAnsi': identifier not found

这是我的 GUI 表单代码,我想使用命令 marshal 但是,它出现在发生错误的地方

    private: System::Void DisplayButton_Click(System::Object^  sender, System::EventArgs^  e) 
     {
         int InitProductID = 0;
         char* InitDescription;
         int InitManufID = 0;
         double InitWholeSale = 0.0;
         double InitMarkup = 0.0;
         int InitQuanity = 0;

         String^ TypeString;

         //EXTRACT FROM INPUT TEXT BOX'S
         InitProductID = Convert::ToInt32(ProductIDNumberBoxNew->Text);
         InitDescription = (char*)(void*)Marshal::StringToHGlobalAnsi(DescriptionBox->Text);
         InitManufID = Convert::ToInt32(ManufacturerBox->Text);
         InitWholeSale = Convert::ToDouble(WholesalePriceBox->Text);
         InitMarkup = Convert::ToDouble(MarkupBox->Text);
         InitQuanity = Convert::ToInt32(QuantityBox->Text);

         //CREATE INSTANCE OF CLASS
         Inventory InventoryItem(InitProductID, InitDescription, InitManufID, InitWholeSale, InitMarkup, InitQuanity);

         //DISPLAY TO OUTPUT TEXT BOXS
         ProductIDNumberOutBox->Text = Convert::ToString(InventoryItem.GetProductID());
         TypeString=gcnew String(InventoryItem.GetDescription());
         ManufacturerOutBox->Text = Convert::ToString(InventoryItem.GetManufID());
         //RETAIL PRICE OUTBOX
         QuantityOutBox->Text= Convert::ToString(InventoryItem.GetQuanity());


     }

下面是我的 stdafx 头文件

 #pragma once

 // TODO: reference additional headers your program requires here
 #include "Inventory.h"

下面是我的 stdafx cpp 文件

#include "stdafx.h"
#include "Form1.h"

最后这是我的库存头文件

//SPECIFICATION FILE (INVENTORY.H)
#ifndef INVENTORY_H
#define INVENTORY_H

#include <iostream>
#include <iomanip>

  using namespace std;

 class Inventory 
 {
 private:
int ProductID;
mutable char Description[25];
int ManufID;
double WholeSale;
double Markup;
int Quanity; 

public:
//CONSTRUCTORS
Inventory( );
Inventory(int, char[], int, double, double, int);

//GET FUNCTIONS
int GetProductID( )const;
char* GetDescription( )const;
int GetManufID( )const;
double GetWholeSale( )const;
double GetMarkup( )const;
int GetQuanity( )const;

//DISPLAY FUNCTION
void Display( )const;

//RETURN FUNCTION
double RetailPrice( )const;

};
#endif

最佳答案

我认为你需要引用这个:

using namespace System::Runtime::InteropServices;

关于C++ 图形用户界面 - 'Marshal' : is not a class or namespace name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19698474/

相关文章:

c++ - 了解 LeakSanitizer 输出

c++ - OpenCV:Orb 参数

text - 将文本模型暴露给可编写脚本的环境的 Emacs 替代方案?

c# - PtrToStructure 抛出的参数异常

c# - 将字符串数组从 C++ 传递到 C#

c++ - 在 Makefile 中以编程方式确定库路径

c++ - 无法使用大小和类型参数调用 OpenCV 的 Mat::zeros

java - JAXB - 编码器写入系统输出但不写入 XML 文件

user-interface - Windows 的 UI 自动化工具(嵌入在 Windows 应用程序中的网页)

python - 如何在 PySide 中强制重新绘制?