Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Go Back  Xtreme Visual Basic Talk > > > Can arrays be part of WIN API declarations?


Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2015, 09:14 PM
chemisthans chemisthans is offline
Newcomer
 
Join Date: Oct 2009
Posts: 3
Question Can arrays be part of WIN API declarations?


I am trying the get rid of "AsAny" variables in my Windows API calls in preparation for migrating my VB6 program to VB.NET. What I am doing is placing Integers (among other data types) in a byte array for storage (the byte array is then written to disk). I then read the data back from the byte array when I need it. I have been using:

Private Declare Sub hmemcpy Lib "Kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvsource As Any, ByVal cbCopy As Long)

This works perfectly and is very fast with all data types (including entire arrays) with the following code, where PtrByt is the location in the Byte array where I want the integer stored.

call hmemcpy (bytDest(PtrByt), SrcInt as Integer, 2)

Since you can't use "AsAny" in VB.NET, I was planning to create a bunch of specific declarations for each data type to ease the conversion, as follows

Private Declare Sub hmemcpyInt2BytArry Lib "Kernel32" Alias "RtlMoveMemory" _
(byt() As Byte, SrcInt As Integer, ByVal cbCopy As Long)

But when I use this function in VB6, it gives an error: Type mismatch: array or user-defined type expected.

Call hmemcpyInt2BytArry(bytDest(PtrByt), SrcInt, 2) ' ERROR

I am certain that all of the variables are declared correctly - bytDest is a byte array, SrcInt is an integer, PtrByt is a long. Is what I am doing not permitted - i.e. declaring an API function with an array as an argument? Or am I doing it wrong?
Reply With Quote
  #2  
Old 11-01-2015, 09:32 PM
chemisthans chemisthans is offline
Newcomer
 
Join Date: Oct 2009
Posts: 3
Default Arrays in API declarations - figured out my wrong thinking

OK, I got why this doesn't run - I declared a byte array, but am actually passing a single byte. Works fine when I change the declaration to:

Private Declare Sub hmemcpyInt2BytArry Lib "Kernel32" Alias "RtlMoveMemory" _
(byt As Byte, SrcInt As Integer, ByVal cbCopy As Long)

So now the question is, will this work in VB.NET to copy integers, singles, longs, strings and entire arrays of singles and integers into a byte array?
Reply With Quote
  #3  
Old 11-07-2015, 05:18 PM
fafalone fafalone is offline
Freshman
 
Join Date: May 2010
Posts: 37
Default

You can declare an array outright in an API. Although frequently you'll need to just leave it as a Long and pass a reference to the first member:
Code:
Private Function StringToIntArray(strIn As String) As Integer()
    Dim intOut() As Integer
    ReDim intOut(0 To Len(strIn) - 1) As Integer

    CopyMemory intOut(0), ByVal StrPtr(strIn), Len(strIn) * 2
    StringToIntArray = intOut
End Function
Reply With Quote
Reply

Tags
array, byte, srcint, integer, data, api, type, hmemcpy, function, private, declare, ptrbyt, call, alias, kernel32, rtlmovememory, byval, cbcopy, lib, error, vb6, vb.net, variables, asany, arrays


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations? Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
 
Can arrays be part of WIN API declarations?
Can arrays be part of WIN API declarations?
 
-->