惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Vercel News
Vercel News
C
Check Point Blog
G
Google Developers Blog
博客园 - 司徒正美
量子位
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
A
About on SuperTechFans
美团技术团队
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Cloudflare Blog
U
Unit 42

博客园 - sunrack

LINQ to SQL语句之Group By/Having和Exists/In/Any/All/Contains ASPxPopupControl does not show up in the right place 程序员从初级到中级10个秘诀 Get JavaScript IntelliSense With DevExpress Client-Side Objects - v2010 vol 1 Grid Editing - Cascading Combo Boxes - sunrack ASPxRadioButtonList 报错解决办法 - sunrack - 博客园 本地连接属性“出现意外错误”的解决办法 - sunrack - 博客园 Bootstrap DotNetFX35SP1 in Visual Studio 2010 Windows Server 2008 共享策略 XtraPivotGrid Custom Summaries 手动注册 DevExpress 8.2.3 控件到 Visual Studio 工具箱 sn.exe error "Failed to generate a strong name key pair -- The keyset is not defined" Thread Tools Rate Thread 浅析JavaScript中的showModalDialog的实战应用 javascript showModalDialog模态对话框使用说明 - sunrack - 博客园 entity framework 缓存干扰的数据不一致问题 Failed to load viewstate ? Typical problem, with an obvious solution. ViewState and Dynamic Control ASPxGridView 和 AJAX Extensions ToolBox 不兼容 ASPxCombobox Features
C++/CLI托管字符串与非托管char数组的转换
sunrack · 2011-01-11 · via 博客园 - sunrack

CLI

显示行号 复制代码 这是一段程序代码。

  1. // CLR.Dll.h
    
  2. 
    
  3. #pragma once
    
  4. #include "string.h"
    
  5. 
    
  6. 
    
  7. using namespace System;
    
  8. using namespace System::Runtime::InteropServices;
    
  9. namespace CLRDll {
    
  10.     public ref class DllClass
    
  11.     {
    
  12.     public:
    
  13.         String^ FunctionTest(String^ input)
    
  14.         {
    
  15.             char* inputChar = ManagedString2UnmanagedStringA(input);
    
  16.             //call native c++ function...
    
  17.             inputChar[0] = 'A';
    
  18.             String^ result = UnmanagedStringA2ManagedString(inputChar);
    
  19.             return result;
    
  20.         }
    
  21.     private:
    
  22.         //将?非?托D管ü的?ANSI字?符?串?转a换?成é托D管ü字?符?串? 
    
  23.         String^ UnmanagedStringA2ManagedString(char* pIn)
    
  24.         {
    
  25.             return Marshal::PtrToStringAnsi(static_cast<IntPtr>(pIn));
    
  26.         }
    
  27.         //将?托D管ü字?符?串?转a换?成é非?托D管ü的?ANSI字?符?串? 
    
  28.         char* ManagedString2UnmanagedStringA(String^ strIn)
    
  29.         {
    
  30.             IntPtr ip = Marshal::StringToHGlobalAnsi(strIn);
    
  31.             const char* pTemp = static_cast<const char*>(ip.ToPointer());
    
  32.             char *pOut = new char[strlen(pTemp)+1];
    
  33.             strcpy(pOut, pTemp);
    
  34.             Marshal::FreeHGlobal(ip);
    
  35.             return pOut;
    
  36.         } 
    
  37.     };
    
  38. }
    

C#

显示行号 复制代码 这是一段程序代码。

  1. public void RunTest()
    
  2. {
    
  3.     DllClass curDllClass = new DllClass();
    
  4.     string input = "test";
    
  5.     string output = curDllClass.FunctionTest(input);
    
  6. }