0

I have

c++ api function :

 `int readMemory(unsigned int address, unsigned char** data, unsigned int size);` 

I want to translate it into vb.net function:

Public Function readMemory(
        ByVal address As UInteger, ByRef data As IntPtr, ByVal size As UInteger) As Integer
End Function

When I call readMemory function in vb.net:

Dim startAddress As UInteger = &H801FFFA
Dim dataStruct As IntPtr 
Dim size As Integer = 1
Dim readMemoryFlag As Integer = 0
 
 readMemoryFlag = readMemory(startAddress, dataStruct, 0)

Then I getting

access violation exception

. When I declare startAddress as Uint64 then I not getting the exception but size is very random. Any help ?

Luke W
  • 1
  • 2
  • Is there a specific reason you resort to a C++ DLL to read memory instead of using [.NET's MemoryStream class](https://learn.microsoft.com/en-us/dotnet/api/system.io.memorystream?redirectedfrom=MSDN&view=net-7.0)? – Hel O'Ween Jan 17 '23 at 12:58
  • readmemory is a API function of stm32cubeprogrammer library and I using it for read bytes from connected device – Luke W Jan 17 '23 at 13:08
  • With typical C++ compiler settings, I would expect that your original type mappings are correct, and it's not surprising that `size` would be weird if you intentionally mismatch the type sizes. What level of debugging have you done on this? Can you do mixed mode debugging and see what happens on the native side? Do you reach the native side with the original declaration? – Craig Jan 17 '23 at 20:20
  • Thanks for reply. I can't see what happens on the native side because I haven't symbol file of library (*.pdb). – Luke W Jan 18 '23 at 06:45
  • Also I haven't source files of library - only dll . – Luke W Jan 18 '23 at 07:32
  • You could try writing a substitute which exports a routine with the same signature. Then you'll have pdb and source and be able to step into it. One of the C++ project templates with Visual Studio is for a dll, and it should be relatively trivial to add an export to it. – Craig Jan 18 '23 at 14:06

0 Answers0