如果我在文本框中输入了数值,我需要代码将字符串类型数据转换为整数类型数据.我正在使用visual c ++ windows窗体和visual studio
今天我看到了以下语法.任何人都可以告诉我这个意思:
System::ComponentModel::Container ^components;
Run Code Online (Sandbox Code Playgroud)
在使用向导创建服务之后,我在Visual C++中获得了此代码.
任何人都可以帮忙
我需要一个在C++/CLI中使用的通用方法.
我现在尝试以下方法:
generic<K, ref class U>
void OnUpdate (
K key,
U update
);
Run Code Online (Sandbox Code Playgroud)
可悲的是,它不起作用.该方法必须接受K和U,并且C#定义是:
void DataUpdate<K, U>(DataUpdate<K, U> update) where U : class;
Run Code Online (Sandbox Code Playgroud)
(是的,方法不同 - OnUpdate将检查接口的某个点是否已设置,然后在接口中调用此方法,就像事件处理程序一样,因此参数必须匹配).
C++/CLI中的通用语法使我无法理解.我也没有问题将K定义为一个类.
我正在尝试将C++中的图像发送到C#,并使用C++管理的互操作(编组).从字符串image->getStream()返回a const char*.
我的Marshal::Copy功能异常.
'System.AccessViolationException'mscorlib.dll中发生了未处理的类型异常附加信息:尝试读取或写入受保护的内存.这通常表明其他内存已损坏.
我是否正在从复制const char*到字节数组做正确的事情?我的dll是在VS2010中使用ASCII字符集编译的.
array<System::Byte>^ OsgViewer::getLastImage()
{
array< Byte >^ byteArray;
m_ImageQueue->lock();
int index = m_ImageQueue->getCurrentImageIndex();
std::shared_ptr<Image> image = m_ImageQueue->getImage(static_cast<unsigned int>(index));
if( image && image->isValid() == true)
{
int wLen = image->getStreamSize();
char* wStream = const_cast<char*>(image->getStream());
byteArray = gcnew array< Byte >(wLen);
// convert native pointer to System::IntPtr with C-Style cast
Marshal::Copy((IntPtr)wStream ,byteArray , 0, wLen);
}
m_ImageQueue->unlock();
return byteArray;
}
Run Code Online (Sandbox Code Playgroud)
Image是一个自制的C++类
class ADAPTER Image
{
public : …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作我的第一个Windows窗体应用程序.我正在尝试建立SQL连接,所以我插入了我的SQL函数,它在控制台应用程序中完美运行.我重写了一点,但是现在,我收到链接器错误,我不知道为什么.
有人可以帮助我,我做错了什么?
谢谢!
误差修改:
Error 3 error LNK2028: unresolved token (0A000023) "extern "C" short __stdcall SQLGetData(void *,unsigned short,short,void *,long,long *)" (?SQLGetData@@$$J224YGFPAXGF0JPAJ@Z) referenced in function "private: bool __clrcall Test_WindowsForm::Form1::ExecuteSQLCommand(void)" (?ExecuteSQLCommand@Form1@Test_WindowsForm@@$$FA$AAM_NXZ) Test_WindowsForm.obj
Error 4 error LNK2028: unresolved token (0A000024) "extern "C" short __stdcall SQLFetch(void *)" (?SQLFetch@@$$J14YGFPAX@Z) referenced in function "private: bool __clrcall Test_WindowsForm::Form1::ExecuteSQLCommand(void)" (?ExecuteSQLCommand@Form1@Test_WindowsForm@@$$FA$AAM_NXZ) Test_WindowsForm.obj
Error 5 error LNK2028: unresolved token (0A000025) "extern "C" short __stdcall SQLRowCount(void *,long *)" (?SQLRowCount@@$$J18YGFPAXPAJ@Z) referenced in function "private: bool __clrcall Test_WindowsForm::Form1::ExecuteSQLCommand(void)" (?ExecuteSQLCommand@Form1@Test_WindowsForm@@$$FA$AAM_NXZ) Test_WindowsForm.obj
Error 6 error …
我基本上试图在visual studio 2008中编写一个基本的转换器,我有两个文本框,一个用户输入,另一个用输出结果.当我按下按钮时,我希望第一个文本框中的输入乘以4.35然后显示在第二个文本框中.到目前为止,这是我在按钮代码中的代码:
String^ i1 = textBox1->Text;
float rez = (i1*4.35)ToString;
textBox2->Text = rez;
Run Code Online (Sandbox Code Playgroud)
但是我收到这些错误:
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(148) : error C2676: binary '*' : 'System::String ^' does not define this operator or a conversion to a type acceptable to the predefined operator
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(148) : error C2227: left of '->ToString' must point to class/struct/union/generic type
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(149) : error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'float' to 'System::String ^'
Run Code Online (Sandbox Code Playgroud)
请帮助我疯狂地从C++中的文本框中获取一些输入是多么的荒谬.我用谷歌搜索了我的每一个错误,没有任何有用的信息,我已经找了一个小时的答案,请帮忙.
我最近将一个项目从.NET 3.5移到了.NET 4.我使用的是C#,托管C++和非托管C++.
在我的一个托管C++(互操作)中,我有一个静态构造函数:
public ref class StaticPool : public BaseStaticPools
{
public:
static StaticPool()
{
InitializePools();
}
static Poolable^ Dequeue()
{
return (Poolable^)Dequeue(Poolable::typeid);
}
private:
static void InitializePools()
{
BaseStaticPools::CreatePool(Poolable::typeid);
}
};
Run Code Online (Sandbox Code Playgroud)
在.NET 3.5中曾经Dequeue()第一次调用它会触发静态初始化,它会运行静态构造函数.一旦我转移到.NET 4.0,从未调用静态构造函数.
我知道.NET 4.0中的静态初始化已经发生了变化,但根据我读到的所有内容,它应该可以正常工作.
- 我试图在c ++/cli中使用事件处理程序来抛出事件然后在c#中订阅它
class Mclass
{
event System::EventHandler ^ someEvent;
void ShowMessage(System::String ^)
{
someEvent(this,message);
}
}
Run Code Online (Sandbox Code Playgroud)
- 但它会引发错误
错误C2664:'managed :: Mclass :: someEvent :: raise':无法将参数2从'System :: String ^'转换为'System :: EventArgs ^'
如何纠正它
以下C++/CLI代码将nullptr返回给pKey.
RegistryKey^ pKey = Microsoft::Win32::Registry::LocalMachine->OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Folders");
Run Code Online (Sandbox Code Playgroud)
下面的C#代码返回一个指向pKey的有效指针.
RegistryKey pKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Folders");
Run Code Online (Sandbox Code Playgroud)
除了语言差异外,这两个代码片段看起来与我完全相同.
我只是想通过在x64中构建C++代码可以找到密钥.所以我现在的问题是如何在32位版本中找到密钥?我需要在两个版本中找到它.
谢谢.
我有一个第三方C库,我需要在C#中使用它.系统的其余部分是用C#编写的,因此使用C++/CLI只是包装器的一个选项.
使用C++/CLI包装C库而不是C#有什么好处?创建C#-wrapper有什么好处吗?
这些库包含一些结构,一些枚举和许多函数.
编辑:是否可以在C#中使用C结构和枚举而不包装它们?