cstring

PInvoke with a CString

北城余情 提交于 2019-12-02 19:51:12
问题 I'm trying to use P/Invoke to call functions in an unmanaged C++ DLL from C#. The C++ DLL uses CString 's as function parameters and returns, such as CString AFX_EXT_API GetUserName(CString& userID) Unfortunately, the C++ is legacy code that I cannot change to use the more universal LPSTR (or even char * ). Is there any way to marshal the CString into a .NET compatible object? Or somehow decorate a .NET char[] to be marshaled to a CString? 回答1: You can't create a CString in managed code. So

How do I pass this array of c strings correctly? [closed]

隐身守侯 提交于 2019-12-02 14:41:07
I have my array of C-Strings declared as: char *argv[MAXARGS]; MAXARGS basically just tells us how many c strings are in the array for indexing purposes. I want to pass it to this function below... int builtin_cmd(char **argv) but nothing seems to go through, I called the function like this. char *argv[MAXARGS]; builtin_cmd(argv); but once i get into the function builtin_cmd and try to print using printf("%s\n", argv[0]); it prints nothing.... but when i do this before calling the function... char *argv[MAXARGS]; printf("%s\n", argv[0]); //builtin_cmd(argv); it will print the first C string in

PInvoke with a CString

混江龙づ霸主 提交于 2019-12-02 12:33:00
I'm trying to use P/Invoke to call functions in an unmanaged C++ DLL from C#. The C++ DLL uses CString 's as function parameters and returns, such as CString AFX_EXT_API GetUserName(CString& userID) Unfortunately, the C++ is legacy code that I cannot change to use the more universal LPSTR (or even char * ). Is there any way to marshal the CString into a .NET compatible object? Or somehow decorate a .NET char[] to be marshaled to a CString? You can't create a CString in managed code. So clearly you need an extra layer between the managed code and the native code. This gives you an opportunity

how to perform reversing a sentence Word by Word in C?

陌路散爱 提交于 2019-12-02 09:47:32
问题 #include <stdio.h> int main(void) { int i,j; int wordstart = -1; int wordend = -1; char words[]= "this is a test"; char temp; // Reverse each word for (i = 0; i < strlen(words); ++i) { wordstart = -1; wordend = -1; if(words[i] != ' ') wordstart = i; for (j = wordstart; j < strlen(words); ++j) { if(words[j] == ' ') { wordend = j - 1; break; } } if(wordend == -1) wordend = strlen(words); for (j = wordstart ; j <= (wordend - wordstart) / 2; ++j) { temp = words[j]; words[j] = words[wordend - (j -

how to perform reversing a sentence Word by Word in C?

非 Y 不嫁゛ 提交于 2019-12-02 07:14:12
#include <stdio.h> int main(void) { int i,j; int wordstart = -1; int wordend = -1; char words[]= "this is a test"; char temp; // Reverse each word for (i = 0; i < strlen(words); ++i) { wordstart = -1; wordend = -1; if(words[i] != ' ') wordstart = i; for (j = wordstart; j < strlen(words); ++j) { if(words[j] == ' ') { wordend = j - 1; break; } } if(wordend == -1) wordend = strlen(words); for (j = wordstart ; j <= (wordend - wordstart) / 2; ++j) { temp = words[j]; words[j] = words[wordend - (j - wordstart)]; words[wordend - (j - wordstart)] = temp; } i = wordend; printf("reversed string is %s:",

How to marshal the type of “Cstring” in .NET Compact Framework(C#)?

不羁岁月 提交于 2019-12-02 06:32:59
问题 How to marshal the type of "Cstring" in .NET Compact Framework(C#)? DLLname:Test_Cstring.dll(OS is WinCE 5.0),source code: extern "C" __declspec(dllexport) int GetStringLen(CString str) { return str.GetLength(); } I marshal that in .NET Compact Framework(C#),for example: [DllImport("Test_Cstring.dll", EntryPoint = "GetStringLen", SetLastError = true)] public extern static int GetStringLen(string s); private void Test_Cstring() { int len=-1; len=GetStringLen("abcd"); MessageBox.Show("Length:"

How to concatenate multiple CString

元气小坏坏 提交于 2019-12-02 05:38:00
问题 All functions return CString, this is a MFC code and must compile in 32 & 64 bits. Currently I'm using CString sURI = GetURL(); sURI += GetMethod(); sURI += "?"; sURI += GetParameters(); Exists any manner to do the same like: CString sURI = GetURL() + GetMethod() + "?" + GetParameters(); 回答1: Problem is that "?" of type "const char*" is, and its + operator does not take right hand operand of type CString. You have to convert "?" to CString like this: CString sURI = GetURL() + GetMethod() + _T

mfc copy certain sections of a CString

岁酱吖の 提交于 2019-12-02 03:53:32
问题 Let's say I have a CString variable carrying the string "Bob Evans". I want to copy from position 4 until the end of the original CString to a new CString, but I am having trouble finding semantics examples for this: CString original("Bob Evans"); // Below is what I'm trying to do // CString newStr = original.copy(4, original.GetLength()); I have also thought about copying the variable original to a STL C++ string, but achieving this isn't all that easy either in terms of the conversion. What

ECUST_Algorithm_2019_2

旧城冷巷雨未停 提交于 2019-12-02 03:47:00
简要题意及解析 1001 \(N\) 个数分为 \(K+8\) 组,每组三个,记为 \((a,b,c)\) ,方便起见要求 \(a \leq b \leq c\) ,每组的代价是 \((a-b)^2\) ,总代价为每组的代价之和。求最小的总代价。 将所有物品 \(a[i]\) 从小到大排序,从后向前递推。 \(f[i][j]\) 表示在第 \(i\) 个到第 \(N\) 个数中选 \(j\) 组的最小代价。 \(f[i][j]=\min_{N-i+1 \leq 3 \times j} \{f[i+2][j-1]+(a[i+1]-a[i])^2\}\) 时间复杂度 \(O(Tnk)\) \(T\) 为数据组数, \(n\) 为物品个数, \(k\) 为所需组数。 1002 给出三个字符串 \(A,B,C\) ,问从 \(A\) 和 \(B\) 中按照与原顺序抽取一些字符,能不能组成 \(C\) 。 \(f[i][j]\) 表示从 \(A\) 的前 \(i\) 个和 \(B\) 的前 \(j\) 个中随意抽取,最多能组成 \(C\) 的前几位。 \(f[i][j]=\max\{f[i-1][j]+1(if~~A[i]==C[f[i-1][j]+1]),f[i][j-1]+1(if~~B[j]==C[f[i][j-1]+1])\}\) 时间复杂度 \(O(Tnm)\) \(T\)

How to marshal the type of “Cstring” in .NET Compact Framework(C#)?

旧时模样 提交于 2019-12-02 01:09:54
How to marshal the type of "Cstring" in .NET Compact Framework(C#)? DLLname:Test_Cstring.dll(OS is WinCE 5.0),source code: extern "C" __declspec(dllexport) int GetStringLen(CString str) { return str.GetLength(); } I marshal that in .NET Compact Framework(C#),for example: [DllImport("Test_Cstring.dll", EntryPoint = "GetStringLen", SetLastError = true)] public extern static int GetStringLen(string s); private void Test_Cstring() { int len=-1; len=GetStringLen("abcd"); MessageBox.Show("Length:"+len.ToString()); //result is -1,so PInvoke is unsuccessful! } The Method of "GetStringLen" in .NET CF