Re: Call C# DLL using C++ - "Not enough storage is available to complete this operation" [modified]
-
Hello, I want to create a C# DLL that passes out a string as a parameter. I have tried this (partial code): [C# Code] public interface iInterface1 { [System.Runtime.InteropServices.DispId(13)] void Call13( [System.Runtime.InteropServices.In] [System.Runtime.InteropServices.Out] [System.Runtime.InteropServices.MarshalAs( System.Runtime.InteropServices.UnmanagedType.BStr)] ref string s1); [System.Runtime.InteropServices.DispId(17)] void Call17( [System.Runtime.InteropServices.In, System.Runtime.InteropServices.Out, System.Runtime.InteropServices.MarshalAs( System.Runtime.InteropServices.UnmanagedType.LPWStr)] ref System.String s1); } [C++ Code] BSTR s; m_int0.Call13(&s); [C++ Code] LPWSTR s2; m_int0.Call17(&s2); The programs compile, but do not run: The C++ call to Call13 gives me the message "Not enough storage is available to complete this operation". The C++ call to Call17 in Debug mode shows that there is a breakpoint in the program: "This may be due to a corruption of the heap, and indicates a bug in go2.exe or any of the DLLs it has loaded." Does anyone have any ideas? Regards, Mike modified on Wednesday, April 15, 2009 10:23 AM
-
Hello, I want to create a C# DLL that passes out a string as a parameter. I have tried this (partial code): [C# Code] public interface iInterface1 { [System.Runtime.InteropServices.DispId(13)] void Call13( [System.Runtime.InteropServices.In] [System.Runtime.InteropServices.Out] [System.Runtime.InteropServices.MarshalAs( System.Runtime.InteropServices.UnmanagedType.BStr)] ref string s1); [System.Runtime.InteropServices.DispId(17)] void Call17( [System.Runtime.InteropServices.In, System.Runtime.InteropServices.Out, System.Runtime.InteropServices.MarshalAs( System.Runtime.InteropServices.UnmanagedType.LPWStr)] ref System.String s1); } [C++ Code] BSTR s; m_int0.Call13(&s); [C++ Code] LPWSTR s2; m_int0.Call17(&s2); The programs compile, but do not run: The C++ call to Call13 gives me the message "Not enough storage is available to complete this operation". The C++ call to Call17 in Debug mode shows that there is a breakpoint in the program: "This may be due to a corruption of the heap, and indicates a bug in go2.exe or any of the DLLs it has loaded." Does anyone have any ideas? Regards, Mike modified on Wednesday, April 15, 2009 10:23 AM