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

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
量子位
博客园_首页
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Forbes - Security
Forbes - Security
IT之家
IT之家
N
News and Events Feed by Topic
S
Security Affairs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Webroot Blog
Webroot Blog
Recorded Future
Recorded Future
L
LangChain Blog
Y
Y Combinator Blog
AI
AI
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google Online Security Blog
Google Online Security Blog
V2EX - 技术
V2EX - 技术
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
I
Intezer
T
Tenable Blog
G
Google Developers Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
云风的 BLOG
云风的 BLOG
C
CXSECURITY Database RSS Feed - CXSecurity.com
有赞技术团队
有赞技术团队
O
OpenAI News
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
C
Check Point Blog
Last Week in AI
Last Week in AI
S
Schneier on Security
Simon Willison's Weblog
Simon Willison's Weblog
Blog — PlanetScale
Blog — PlanetScale

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