Reputation: 45
I'm trying to create a mixed mode dll with a few function exported for calling managed code from say, Delphi and C++.
I got it working but now I'm only getting System.StackoverflowException in the debugger and I'm wondering what I'm doing wrong.
The code is quite simple
unmanaged.h
#pragma once
#pragma unmanaged
#include <Windows.h>
typedef void (*ByteCallback)(unsigned char * bytes, int len);
namespace Something {
extern "C"{
__declspec(dllexport) void InteropInit(ByteCallback responseCallback, ByteCallback requestInformationCallback);
}
};
unmanaged.cpp
#include "Stdafx.h"
#include "Managed.h"
#include "Unmanaged.h"
#pragma unmanaged
namespace Something{
void InteropInit(ByteCallback responseCallback, ByteCallback requestInformationCallback) {
Something::ManagedInit();
}
};
managed.h
#include "Stdafx.h"
#pragma managed
namespace Something{
void ManagedInit();
};
managed.cpp
#include "Stdafx.h"
#include "Managed.h"
#include <string>
#pragma managed
namespace Something {
void ManagedInit() {
System::Console::WriteLine("Hallo");
};
};
Stacktrace (this goes on and on and on until visual studio wont show any more lines)
ntdll.dll!_RtlpCallVectoredHandlers@12() + 0x2f244 bytes
ntdll.dll!_RtlCallVectoredExceptionHandlers@8() + 0x12 bytes
ntdll.dll!_RtlDispatchException@8() + 0x19 bytes
ntdll.dll!_KiUserExceptionDispatcher@8() + 0xf bytes
ntdll.dll!_RtlpCallVectoredHandlers@12() + 0x2f244 bytes
ntdll.dll!_RtlCallVectoredExceptionHandlers@8() + 0x12 bytes
ntdll.dll!_RtlDispatchException@8() + 0x19 bytes
ntdll.dll!_KiUserExceptionDispatcher@8() + 0xf bytes
Could someone please help me?
Upvotes: 2
Views: 563
Reputation: 1341
I don't know what exatly you're doing, but this
typedef void (*ByteCallback)(unsigned char * bytes, int len);
should be a windows callback function, right? Almost all callbacks use stdcall, so
typedef void (__stdcall *ByteCallback)(unsigned char * bytes, int len);
might make it work. Of course, you need to add __stdcall
to the function you're passing too.
Upvotes: 2