0

I have function PLInsert2D Also it has description in unmanaged code like this:

HRESULT PLInsert2D(
[in] IPARTLibProvider* aPLClient;
[in] IBOResponseDisp* aMethodResponse;
[in] Double aX, aY, aAngle;
[out, retval] long* result); 

I call this function from vb.net vs 2017 win8.1 64bit:

<DllImport("C:\Program Files\ASCON\KOMPAS-3D v17\Libs\PARTLib\Clients\plclient_kompas.dll", BestFitMapping:=True, CallingConvention:=CallingConvention.StdCall, EntryPoint:="LIBRARYENTRY")>
    Public Shared Function PLInsert2D(<MarshalAs(UnmanagedType.Interface)> ByVal aPLClient As IPARTLibProvider, <MarshalAs(UnmanagedType.Interface)> ByVal aMethodResponse As IBOResponse, ByVal aX As Double, ByVal aY As Double, ByVal aAngle As Double) As IntPtr
    End Function

and I use it in managed code like this:

Dim insert2dpart As IntPtr
        insert2dpart = PLInsert2D(aPLClient, aMethodResponse, aX, aY, aAngle)

It returns &H0000000000000001 What is this? Is this good or bad? What can I do with this value? It should return reference of macroelement, but I think this is not what I expect. Any help would be appreciated. Thanks!

Baha Dzhan
  • 11
  • 4
  • It doesn't look like you have any retval, "result" should be the last parameter passed ByRef but it's missing. – Nick Abbot Mar 31 '21 at 18:39
  • @NickAbbot `Public Shared Function PLInsert2D( ByVal aPLClient As IPARTLibProvider, ByVal aMethodResponse As IBOResponse, ByVal aX As Double, ByVal aY As Double, ByVal aAngle As Double, ByRef result as integer) As IntPtr` and use it in managed code: `Dim insert2dpart As IntPtr. Dim result as integer result =1 insert2dpart = PLInsert2D(aPLClient, aMethodResponse, aX, aY, aAngle, result)`? – Baha Dzhan Mar 31 '21 at 20:01
  • Here's a document you may need : [Consuming Unmanaged DLL Functions](https://learn.microsoft.com/en-us/dotnet/framework/interop/consuming-unmanaged-dll-functions) – Xingyu Zhao Apr 01 '21 at 06:19
  • It's declared to return an HRESULT. Since the return value is positive, it's a "success" HRESULT. I think 1 is `S_FALSE`, check the documentation (if available) for what that means, I've worked with code that stupidly uses `S_FALSE` to indicate a failure instead of using an error HRESULT. – Craig Apr 01 '21 at 12:36

0 Answers0