Name 'VarPtr' is not declared.In old vb code

后端 未结 2 1492
孤城傲影
孤城傲影 2021-01-23 04:49

I have a old code in VB.Now I convert it into vb.net.There is a line in a code

Dim pCParameters As Integer

pCParameters = VarPtr(Parameters)

2条回答
  •  庸人自扰
    2021-01-23 05:30

    This is not as straight forward because your variables in .NET are managed. To do exactly what you are asking you need to look at GCHandle.Alloc and pin the variable so it cannot be moved. Then you can get its memory address.
    Something like this (from memory):

    GCHandle handle = GCHandle.Alloc(pCParameters , Pinned )
    IntPtr ptr = handle.AddressOfPinnedObject
    

提交回复
热议问题