managed

Marshall char** to string problem calling unmanaged code from managed code

淺唱寂寞╮ 提交于 2019-12-11 06:54:16
问题 I've this C++ function, bool MyClass::my_function(int num, TCHAR** filepath) I've expose the function as extern "C" { __declspec(dllexport) bool MyFunction(int num, char* filepath[]) { OutputDebugStringA("--MyFunction--"); TCHAR **w_filepath = (TCHAR **)calloc(num, 2* sizeof(TCHAR **)); for(int i = 0; i < num; i++) { OutputDebugStringA(filepath[i]); int len = strlen(filepath[i]) + 1; w_filepath[i] = (TCHAR *)calloc (1, len); ctow(w_filepath[i], filepath[i]); // converts char to WCHAR } bool

How to pass an array of strings from C# to an Oracle stored procedure

旧巷老猫 提交于 2019-12-11 06:03:25
问题 I have the following code to pass a table of strings to the Oracle stored procedure called spTest: using (OracleConnection oracleConnection = new OracleConnection(connectionString)) { oracleConnection.Open(); OracleCommand oracleCommand = new OracleCommand(); oracleCommand.Parameters.Add(new OracleParameter { ParameterName = "eventids", Direction = ParameterDirection.Input, CollectionType = OracleCollectionType.PLSQLAssociativeArray, Value = new string[] { "Test1", "Test2" }, Size = 2,

How to force dbo schema name?

爷,独闯天下 提交于 2019-12-11 05:41:28
问题 I'm using "SQL SERVER PROJECT" in VS 2008 to create UDF in C# Then I'm using DEPLOY command to publish DLL into MS SQL server 2005 All works well except all created UDFs are owned by me (as user) But I wanted to keep dbo schema (eg: dbo.UDF_TEST - not jonny.UDF_TEST) Any idea how to manage thar? 回答1: deploy the UDF from an account that is sysadmin, or dbo on the database. You can build the dll and then manually deploy it by logging into management studio as dbo to the database and running

getting a byte array from a pinned object

心已入冬 提交于 2019-12-11 04:54:21
问题 It is possible to get a pointer from a managed array byte [] buffer = new byte[length + byteAlignment]; GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr ptr = bufferHandle.AddrOfPinnedObject(); is there any way to do the opposite. getting a byte array from a pinned object without copying? 回答1: Sure, that's what Marshal.Copy is for - there is no way (well, no way without copying of some variety) to otherwise get memory between the managed and unmanaged states...well,

C# Managed Unmanaged code

微笑、不失礼 提交于 2019-12-11 03:39:19
问题 I'm trying to understand managed/unmanaged code as it pertains to structs and classes. I have a struct with a property of another struct but its a pointer declaration as in: struct StateInfo { Bitboard board; StateInfo* previous; } I'm converting a C++ project to C#. Anyways, this doesn't work because Bitboard is a class. The error I get is something to the fact that pointers cannot be declared on managed types. If I take out Bitboard from the struct, it's fine. I need it though so I changed

Linking to presentationcore.dll in mixed mode DLL

℡╲_俬逩灬. 提交于 2019-12-10 22:38:05
问题 We have a mixed mode DLL written in C++ which wraps native C++ DLLs and exposes managed classes. In the exposed managed classes, we use method arguments of type Vector3D etc., which are part of PresentationCore.DLL. Therefore, the mixed mode C++ code needs to reference PresentationCore.DLL. We do this via #using <PresentationCore.dll> which requires the project's search path to include the folder PresentationCore.dll lives in. This is bad, because these folders vary on different machines, and

How to convert a unmanaged double to a managed string?

假装没事ソ 提交于 2019-12-10 21:57:11
问题 From managed C++, I am calling an unmanaged C++ method which returns a double. How can I convert this double into a managed string? 回答1: I assume something like (gcnew System::Double(d))->ToString() 回答2: C++ is definitely not my strongest skillset. Misread the question, but this should convert to a std::string, not exactly what you are looking for though, but leaving it since it was the original post.... double d = 123.45; std::ostringstream oss; oss << d; std::string s = oss.str(); This

I get LNK2028 when trying to wrap native c++ class using managed c++

走远了吗. 提交于 2019-12-10 13:45:32
问题 trying to wrap a native cpp class using managed c++ class. all looks good but for some reason it wont compile. getting the following linker errors: Error 25 error LNK2028: unresolved token (0A0002CE) Error 27 error LNK2019: unresolved external symbol Any ideas how do I fix this one ? :\ well, here is a full error of one of the functions: Error 20 error LNK2028: unresolved token (0A0002CF) "public: bool __thiscall RCSclient::ResumeChannel(char *,int,__int64)" (?ResumeChannel@RCSclient@@$$FQAE

C++ declaring a managed variable in a native code

岁酱吖の 提交于 2019-12-10 12:39:38
问题 I have a .NET form, and a native code in my Visual Studio. The problem is: I can't declare a global instance of my .NET form in my native code, like this: Editor^ maineditor; It gives me this problem: error C3145: 'EditorEntry' : global or static variable may not have managed type 'Cube3D::Editor ^' 回答1: Instead of using a global static try making it a static method in a container type ref class ManagedGlobals { public: static Editor^ maineditor = nullptr; }; 回答2: wrap the handle with a

How to send a string by reference to an unmanaged C library that modifies that string?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:38:31
问题 I am new to the world of interacting with unmanaged libraries. I have an unmanaged C function that modifies a string by reference within the function. I'm having trouble passing a string from C# and getting it modified by the C function. Here's the C function: __declspec(dllexport) void __stdcall Test(char* name) { *name = "Bar"; } This is the C# DLL import code: [DllImport(@"C:/blah/mylibrary.dll")] public extern static string Test(string name); This is the code I'm using to call the