Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Access Violation Exception in Marshal.PtrToStructure in vb.net

$
0
0

I have below code snippet, which gets a pointer from a C API which is defined in a dll. Using marshalling I am trying to get the structure array, which is my requirement

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Class vb_menu_dotnet
Public level As Short
Public menu_id As String
End Class
Dim current As IntPtr
Dim outArray As IntPtr
Dim manArray(100) As vb_menu_dotnet
vb_dotnet_get_menu_hierarchy(p_menu_handle, p_apl_id, outArray) //C API call
current = outArray
Dim j As Integer
For j = 1 To 100
manArray(j) = New vb_menu_dotnet()
Marshal.PtrToStructure(current, manArray(j)) //Access Violation Exception

==========

The prototype of C API is as below

vb_dotnet_get_menu_hierarchy(tcodss_handle_t p_menu_handle,char* p_apl_id,vb_menu_dotnet** p_menu_array)
Structure defination :
typedef struct
{
short level;
char* menu_id;
} vb_menu_dotnet;

The same code snippet works when both dll and above code is built with x86 option. But when ran with x64 option i get AccessViolation Exception at, Marshal.PtrToStructure(current, manArray(j))


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>