VB.net Passing a structure to unmanaged dll

我的未来我决定 提交于 2019-12-04 12:08:48

Do you have the source code for getState in the val.dll? If it's written in C or C++, and you have the source code or even just the headers, you could use the P/Invoke Assistant to automatically generate your VB.Net code.

Alternatively... (and please do post the original VB6 structure!)

  • You might need to allocate the arrays before calling getState, e.g. state.arr1 = {0.0, 0.0} etc.
  • The Decimal variable e could cause you a problem. In VB6 this was probably a Currency variable, and Decimal is not an exact equivalent as far as I can remember. There will be a way to tell VB.Net to marshal it like a Currency. Perhaps adding an attribute like this...

Sample code:

 Imports System.Runtime  
 Public Structure Test  
   ''blah blah

   <InteropServices.MarshalAs(InteropServices.UnmanagedType.Currency)> _  
   Dim e As Decimal  

   ''blah blah
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!