pinvoke - DllImport and return parameters -


I'm working on hardware testing. Our test framework has been written in C # The country is using DLL.

We have a C ++ method:

  unsigned characters some method (unsigned long * root status)   

which executes an embedded command and returns the status when the order is completed.

We use the cover

  [DllImport (@ "native.dll", Charset = Charset.exe, Calling Communication = Calling Communication. CDCL] Internal Static Extern Byte SomeMethod (Riff UInt32 Managed Stats)   

This works fine but there is a scenario when someMethod is actually a call Does not execute the command, but it adds to a sequence, then execute a particular command, by pressing ExecuteSequence Could. As the sequence is being executed, C ++ code updates the native status , simply copying the data to the memory referenced by the native status pointer. As the sequence completes the ExecuteSequence method returns, at the moment I believe all data (in this case, the nativeStatus ) has been updated. Will my managed status be updated correctly? I have heard that in this case managed status and original status are not pointing to the same memory Marshaller just after the call is completed nativeState What if a solution does not give a copy? Do I need to use unsold keywords and need to create and execute my code in the defined {} block block? [DllImport (@ "native.dll", Charset = CharSet.Ansi, Calling Communication = Calling Communication. CDEcl)] Internal Fixed Exception Extern Byte SomeMethod (UInt32 * Managed Status) )

So whatever you want is a variable location, Will not change

Yes, you set for this {} . Alternatively, you can pin that variable:

  private UIT g_Pinnable = 0; ... var gc = System.Runtime.InteropServices.GCHandle.Alloc (g_Pinnable, System.Runtime.InteropServices.GCHandleType.Pinned); Try {// Pass 'ref g_Pinnable' to reciprocate the API // again. } Finally {gc.Free (); // g_Pinable to reference can be invalid after this point}    

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -