 |
|
 |
This is very simple and easy to use but when I deploy my application with the Dll which calls my c# code, it gives the following error on some of the machines. "The application failed to initialize properly 0xc0150002". Any idea?
|
|
|
|
 |
|
 |
How to send the byte Array from unmanaged to managed c++ using marshalling please help me
|
|
|
|
 |
|
 |
I kind of struggle for passing a already allocated managed object to non managed code.
I wish to set the object in my unmaned code for later calls using SetAlreadyAllocated
tried
extern "C" DllExport bool SetAlreadyAllocated(MYNS::MainForm^ f);
-> got error C3395: 'SetAlreadyAllocated' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention
also tried an Int32 got from
GCHandle.Alloc(this, GCHandleType.Pinned)
SetAlreadyAllocated(m_ObjectHandle.AddrOfPinnedObject());
(in C#)
but I can not cast the Int32 to MYNS::MainForm in the unmanaged code ...
Kind of stuck ... any hint someone ?
|
|
|
|
 |
|
 |
This article is a very good introduction to the methods that can be used to call C# (or other managed code) from unmanaged C++. It is just unfortunate that it uses the old MC++ syntax instead of the new C++/CLI syntax introduced with Visual Studio 2005.
Here is my attempt at translating the program to the new syntax. Hope I've got it right. Please let me know if I've misunderstood something.
#include "stdafx.h"
#include "Bridge.h"
extern "C" {
#include <string.h>
}
#using "dotNetAssembly\bin\dotNetAssembly.dll"
using namespace System;
using namespace dotNetAssembly;
extern "C"
{
__declspec(dllexport) int __cdecl bridge_function_int(int input)
{
mcDotNetClass^ DotNetObject;
DotNetObject = gcnew mcDotNetClass;
return DotNetObject->test_integer(input);
}
__declspec(dllexport) char *__cdecl bridge_function_string(char *input, int buflen)
{
String^ managed_input = gcnew String(input);
mcDotNetClass^ DotNetObject;
DotNetObject = gcnew mcDotNetClass;
array<unsigned char>^ tmp = System::Text::Encoding::UTF8->GetBytes(DotNetObject->test_string(managed_input));
pin_ptr<unsigned char> value = &tmp[0];
strncpy_s(input, buflen, (const char*) value, buflen);
return input;
}
__declspec(dllexport) int __cdecl bridge_function_array(int *values, int len)
{
Array^ managed_values;
mcDotNetClass^ DotNetObject;
managed_values = Array::CreateInstance(System::Int32::typeid, len);
for (int i = 0; i < len; i++)
{
managed_values->SetValue(values[i], i);
}
DotNetObject = gcnew mcDotNetClass;
return DotNetObject->test_array(managed_values);
}
}
Rennie
|
|
|
|
 |
|
 |
I'm new to C++ and this process has proven invaluable for a problem I've been trying to solve for a week now, so thanks! One question I have is that the 'Bridge' assembly in my scenario would be located on a seperate server to 'BridgeTest'. Is there any way of adding the 'Additional Dependencies' of 'BridgeTest' at runtime? (ie. to read the location from a config file)
|
|
|
|
 |
|
 |
Hi there
I get this unhandled exception
(Unhandled exception at 0x7c81eb33 in BridgeTest.exe: 0xE0434F4D: 0xe0434f4d.)
It hits on the first dll call
-- printf("The return of bridge_function_int is %d\n\n\n",bridge_function_int(5));
All the best
|
|
|
|
 |
|
 |
any responses? I would love to know why this unhandled exception is thrown.
Kind regards
|
|
|
|
 |
|
 |
Did you ever figure this issue out?
|
|
|
|
 |
|
 |
hello , I have this message also , how you solved it ?
|
|
|
|
 |
|
|
 |
|
 |
How did you solve the problem?
|
|
|
|
 |
|
 |
This is a very good solution, unfortunately I have to make it work in compact framwework environment under WindowsCE. But there is no support for managed C++ on smart devices.
Any workaround?
Thanks
|
|
|
|
 |
|
 |
I have a managed windows dll written in c# which shows a simple dialog. This dialog loads info from an unmanaged dll written in c. Everthing works fine when running from a test harness written in c#. However, my c-based test harness triggers an error in debug mode when the unmanaged dll returns from a function trying to return a static char array. If I return 0, it works ok so it seems that unwinding of the stack on this call is problematic. The excact wording in the error dialog says, "Windows has triggered a breakpoint in ...This may be due to a corruption in the heap, and indicates a but in ... or any of the dll's it has loaded. The output window may have more diagnostic information."
My calling code looks like this:
[DllImport("name.dll", EntryPoint = "functionname", SetLastError = false, CharSet = CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
static extern string functionname( string key );
The unmanaged dll has been compiled using unicode and mb char sets and I've tried changing the CharSet.Ansi setting to CharSet unicode and .auto. The actual signature of the function calls for:
const char* functionname(const char* key) and I've tried removing 'const' ness but nothing is working. Any ideas are greatly appreciated.
|
|
|
|
 |
|
 |
Thanks for the excellent article. I assumed that it would be possible to go from a non-mfc console application like this one, to an MFC application easily. So I simply rebuilt the unmanaged caller as an MFC windows app with no other changes, but it crashes on start up. I suspect there is some kind of DLL conflict.
Can you tell us how we can use this same technique in an MFC caller?
many thanks,
|
|
|
|
 |
|
 |
It's what I am looking for.
|
|
|
|
 |
|
 |
You may also get an error at run-time indicating "Undhandled Exception bla bla User Breakpoint"
THis is most likely due to an acknowledge compiler problem. I found this by seeing that the link for the bridge dll flagged an error that required "/NOENTRY"; the warning included these buzzwords "warning LNK4243: DLL containing objects compiled with /clr is not linked with /NOENTRY; image may not run correctly".
After setting /NOENTRY, then received another error, (I lost the warning)
The problem is described as Mixed DLL Loading Problem at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vcconMixedDLLLoadingProblem.asp
The resolution is more thoroughly described at "http://support.microsoft.com/?id=814472"
Larry
"Many Bothans died to bring us this information."
|
|
|
|
 |
|
 |
If you're getting a link problem with the C++ application,
may may have forgotten to add the bridge type library into
the additional dependencies for the unmanaged application
assembly.
Additional Dependencies: "..\common\bridge.lib"
|
|
|
|
 |
|
 |
Its a simple article to show the full sequence. Can I access dotnet classes viz. Collection classes back in my caller application? What should I do for that?
KK
|
|
|
|
 |
|
 |
Try not to pass any types that are too complex between .NET and C++. For example, pass your collection as an array if possible.
|
|
|
|
 |
|
 |
It's such a pain to link managed and unmanaged code, thank you very much for the tip !
|
|
|
|
 |
|
 |
To bad it doesn't work when a Single Threaded Apartment is needed to call COM components...otherwise nice work!
|
|
|
|
 |
|
 |
To follow-up on my own post, you just have to make a new thread in your .NET code.
C#:
Thread staThread = new Thread(main);
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
// wait for the thread to exit here
|
|
|
|
 |
|
 |
I need to call a .net assembly from an ATL project using Gdiplus. I can get a Gdiplus.Graphic* pointer, but the function call need a System.Drawing.Graphics*, what should I do?
|
|
|
|
 |
|
 |
I'm trying to use this way to wrap c# code and use it from Powerbuilder 6.5. But I get a problem calling any dll function from PB as soon as I call function with parameters.
This is C++ code I created:
#include "stdafx.h"
#include "Bridge.h"
extern "C" {
#include
#include
}
using namespace System;
extern "C"
{
__declspec(dllexport) int __stdcall SetX( short buflen)
{
return 1;
}
I am defining external function in PB App:
function ulong SetX(int str) LIBRARY "Bridge.dll"
And call it in PB code:
integer result
result = SetX (result)
This is the Powerbuilder I receive:
R0042: Specified argument type differs from required argument type at runtime in DLL function . One of the external function arguments except a value of another type.
I’m afraid the problem is with the data type I use in C++ definition. But I cannot find rite way.
Does any one know the solution? I know it possible to call C++ dll from Powerbuilder, but I could not find any examples.
Please, HELP
Thanks
Valery
|
|
|
|
 |
|
 |
use "int PASCAL" instend of "int __stdcall "
hvmbmn
|
|
|
|
 |