[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] Problems with MarshalAs or/and InteropServices Functio
From: |
Dmitriy |
Subject: |
[Pnet-developers] Problems with MarshalAs or/and InteropServices Function Table (Delegates) |
Date: |
Fri, 16 Apr 2004 01:13:32 +0600 |
Description of Problem:
When Marhaling to native code of functions table error appears.
source sample:
//testdll.dll c++ source
#include "stdio.h"
#define _DLL_EXPORT extern "C" __declspec( dllexport )
typedef void (__stdcall *call_back_type)();
//typedef void (__cdecl *call_back_type)();
struct TD
{
int type;
call_back_type t;
//here may be other functions
};
_DLL_EXPORT void* test(void *o,int i,TD t)
{
printf("%x %d %d\n",(unsigned long)o,i,t.type);
t.t();
return o;
}
//end of testdll.dll source
//test.exe C# source
using System;
using System.Runtime.InteropServices;
namespace testch
{
class Class1
{
[ StructLayout( LayoutKind.Sequential )]
public struct delegate_wrapper
{
public int type;
public delegate void CTest();
[MarshalAs(UnmanagedType.FunctionPtr)] public CTest Test;
static void WTest()
{ Console.WriteLine("test"); }
//here may be other functions with params...
internal delegate_wrapper(int _type)
{
type=_type;//fill this !!!
Test=new CTest(WTest);
}
}
[DllImport("testdll.dll")]
public static extern void test(int a,int i,delegate_wrapper c);
[DllImport("testdll.dll",EntryPoint="test")]
public static extern void test2(int a,int i,int
type,delegate_wrapper.CTest c);
static void Main(string[] args)
{
delegate_wrapper t=new delegate_wrapper(10);
test(10,5,t); //correct way but not work Under
//MONO and Portable.NET
//test2(10,5,t.type,t.Test);
//Incorrect way but work anywhere
}
}
}
Actual Results:
Exception: STATUS_ACCESS_VIOLATION at eip=10227FE8
eax=00000007 ebx=01131000 ecx=0113107A edx=0113AE68 esi=0000000A
edi=10035014
ebp=0022EAA8 esp=0022EA8C program=D:\Programs\PNET\bin\ilrun.exe
cs=001B ds=0023 es=0023 fs=0038 gs=0000 ss=0023
Stack trace:
Frame Function Args
0022EAA8 10227FE8 (004BDC10, 0022EAD0, 00000010, 00000000)
0022EAE8 004BDE3F (10098398, 01131000, 00000000, 0022ED50)
0022EDF8 00425796 (10034F60, 1007C6B8, 00000000, 00000000)
0022EE28 00412A1A (10034F60, 1007C6B8, 00412800, 0022EED8)
0022EE58 00412E86 (10034F60, 1007C6B8, 0022EED8, 0022EEE8)
0022EF10 00401D0E (00000002, 100201C8, 100200A8, 00000001)
0022EF80 61005DE0 (0022EF98, FFFFFFFF, 00000000, 00245780)
0022FF90 61005EE5 (00000000, 00000000, 00000000, 00000000)
End of stack trace
Expected Results:
"
a 5 10
test
"
without exceptions and errors
How often does this happen?
everytime
Additional Information:
compile strings (microsoft compilers used):
cl /LD testdll.cpp
csc test.cs
run strings:
mono test.exe
test.cs
Description: Text document
testdll.cpp
Description: Text document
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pnet-developers] Problems with MarshalAs or/and InteropServices Function Table (Delegates),
Dmitriy <=