How to use RtlMOveMemory in VB.NET?
-
Hi, I have an old VB6 solution where I access a C dll that returns a pointer to a string. It looks like this: dim source as long dim sQuery as string source = IS_DLL_SendAndReceive(tSendBuf, tSendLen, tResult, tReclen) sQuery = Space$(1300) RtlMoveMemory StrPtr(sQuery), source, 2600) Query = StrConv(sQuery, vbUnicode) 'From ASCII to Unicode How can I achieve the same result in VB.NET? I've tried with the Marshal Object and the Encoding class but I can't get it to work :( /Jes.
-
Hi, I have an old VB6 solution where I access a C dll that returns a pointer to a string. It looks like this: dim source as long dim sQuery as string source = IS_DLL_SendAndReceive(tSendBuf, tSendLen, tResult, tReclen) sQuery = Space$(1300) RtlMoveMemory StrPtr(sQuery), source, 2600) Query = StrConv(sQuery, vbUnicode) 'From ASCII to Unicode How can I achieve the same result in VB.NET? I've tried with the Marshal Object and the Encoding class but I can't get it to work :( /Jes.
In VB.6 you can use the generic copy memory routine such as Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (ByRef Destination As Any, ByRef Source As Any, ByVal numbytes As Long) VB.Net rejects the Any and won't work. You have to get more specific, such as Public Declare Sub CM_Integer_Byte Lib "Kernel32" Alias "RtlMoveMemory" _ (ByRef Destination As Integer, ByRef Source As Byte, ByVal Length AsInteger) Public Declare Sub CM_Short_Byte Lib "Kernel32" Alias "RtlMoveMemory" _ (ByRef Destination As Short, ByRef Source As Byte, ByVal Length As Integer) I have a bunch of these in my applications and they work well. RCarey RCarey