c 呼叫c語言dll,形參有char

2021-06-23 00:04:30 字數 1906 閱讀 3897

c#呼叫c語言dll,形參有char*,無法獲得char*內容。但是在c++中呼叫dll無問題。說明dll正確,c#中**有問題。

直接解決方法:未解決,dll沒問題,就是呼叫後儲存在webtoken中讀取有問題,求大神告知解決方法:

變相解決方法:修改dll檔案,將形參char*作為返回值char*返回。

原先的c函式宣告:

#ifndef _dllmain_h  

#define _dllmain_h

#ifndef dll_export

#define _libapi __declspec(dllexport)

#else

#define _libapi __declspec(dllimport)

#endif

#ifdef __cplusplus

extern "c"

#endif

#endif /* _dll_h_ */

原先的呼叫方式:無法獲得webtoken中的字串。

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.threading.tasks;

using system.windows.forms;

using system.runtime.interopservices;

private void button1_click(object sender, eventargs e)

}}

修改後的c函式宣告:

#ifndef _dllmain_h  

#define _dllmain_h

#ifndef dll_export

#define _libapi __declspec(dllexport)

#else

#define _libapi __declspec(dllimport)

#endif

#ifdef __cplusplus

extern "c"

#endif

#endif /* _dll_h_ */

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.threading.tasks;

using system.windows.forms;

using system.runtime.interopservices;//add

namespace testgetwebtoken

private void button1_click(object sender, eventargs e)

}}

總結:1. const char* 直接換成string

2. char*做形參或返回值,需要換成intptr

3. char*做形參並想要獲取char*內容,使用ref intptr無用。只能將該char*改為返回值獲得。

C語言 有參巨集

說明 紅色箭頭表示的意思是 巨集展開 形參用實參換,其它字元保留 巨集體及各形參外一般應加括號 如 1 帶參巨集定義的一般格式 define 巨集名 形參表 語言符號字串 2 帶參巨集的呼叫和巨集展開 1 呼叫格式 巨集名 實參表 2 巨集展開 用巨集呼叫提供的實參字串,直接置換巨集定義命令列中 相...

C語言 有參巨集

說明 紅線的意義 巨集展開 形參用實參換,其它字元保留 巨集體及各形參外一般應加括號 1 帶參巨集定義的一般格式 define 巨集名 形參表 語言符號字串 2 帶參巨集的呼叫和巨集展開 1 呼叫格式 巨集名 實參表 2 巨集展開 用巨集呼叫提供的實參字串,直接置換巨集定義命令列中 相應形參字串,非...

C語言程式設計的形參

本文 http www.songzhige.com post 539.html 其實我對c語言程式設計中形參的使用,有時也是反暈,今天發現這篇文章,很好。今天我們來剖析一道c語言的面試題,這道題除了考察對c語言函式形參的理解外,還有對 這類操作先加還是後加掌握程度的考察。題目見下,可以直接用vc進行...