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

推荐订阅源

N
Netflix TechBlog - Medium
I
Intezer
人人都是产品经理
人人都是产品经理
F
Full Disclosure
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
博客园 - 司徒正美
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
L
LangChain Blog
Last Week in AI
Last Week in AI
B
Blog
Project Zero
Project Zero
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
U
Unit 42
B
Blog RSS Feed
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Privacy International News Feed
N
News and Events Feed by Topic
W
WeLiveSecurity
Cloudbric
Cloudbric
G
GRAHAM CLULEY
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Check Point Blog
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Latest news
Latest news
S
Secure Thoughts
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 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. }