CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: type conversion

  1. #1

    type conversion


    'BOOL HttpSendRequestEx(
    ' IN HINTERNET hRequest,
    ' IN LPINTERNET_BUFFERS lpBuffersIn,
    ' OUT LPINTERNET_BUFFERS lpBuffersOut,
    ' IN DWORD dwFlags,
    ' IN DWORD dwContext
    ');
    'typedef struct _INTERNET_BUFFERS {
    ' DWORD dwStructSize;
    ' struct _INTERNET_BUFFERS% * next;
    ' LPCTSTR lpcszHeader;
    ' DWORD dwHeadersLength;
    ' DWORD dwHeadersTotal;
    ' LPVOID lpvBuffer;
    ' DWORD dwBufferLength;
    ' DWORD dwBufferTotal;
    ' DWORD dwOffsetLow;
    ' DWORD dwOffsetHigh;
    '} INTERNET_BUFFERS, * LPINTERNET_BUFFERS;



    anyone know how to convert those to vb types.. so i can call these functions?


  2. #2
    Join Date
    Sep 1999
    Location
    Orlando, FL
    Posts
    3

    Re: type conversion

    NewString = StrConv(<string>,vbFromUnicode)

    Try that...

    Kurt


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: type conversion

    Try this: Am not sure but...

    The Structure goes as:
    'typedef struct _INTERNET_BUFFERS {
    ' DWORD dwStructSize;
    ' struct _INTERNET_BUFFERS% * next;
    ' LPCTSTR lpcszHeader;
    ' DWORD dwHeadersLength;
    ' DWORD dwHeadersTotal;
    ' LPVOID lpvBuffer;
    ' DWORD dwBufferLength;
    ' DWORD dwBufferTotal;
    ' DWORD dwOffsetLow;
    ' DWORD dwOffsetHigh;
    '}

    type struct INTERNET_BUFFERS_VB
    dwStructSize as long
    next as long ' but actually lpINTERNET_BUFFERS ;
    lpcszHeader as long
    dwHeadersLength as long
    dwHeadersTotal as long
    lpvBuffer as long
    dwBufferLength as long
    dwBufferTotal as long
    dwOffsetLow as long
    dwOffsetHigh as long
    end type




    The function definition transforms like this:
    'BOOL HttpSendRequestEx(
    ' IN HINTERNET hRequest,
    ' IN LPINTERNET_BUFFERS lpBuffersIn,
    ' OUT LPINTERNET_BUFFERS lpBuffersOut,
    ' IN DWORD dwFlags,
    ' IN DWORD dwContext
    ');

    Declare Function HttpSendRequestEx Lib "???" (
    byval hRequest as long, _
    lpBuffersIn as Any, lpBuffersOut as Any , _
    byval dwFlags as long, byval dwContext as long) as long



    The definitions willl go thru. But care should be taken before and after calling the fn.
    Like:
    1. dim ttt as INTERNET_BUFFERS_VB, tmpbuf as string
    dim ttt1 as INTERNET_BUFFERS_VB
    2.
    tmpbuf = space(256)
    ttt.dwStructSize = Len(ttt)
    ttt.lpcszHeader = StrPtr(tmpbuf) ''<<--****
    ttt.dwHeadersLength = Len(tmpbuf)
    ttt.Next = VarPtr(ttt1) ''<<--****

    3. dim ttt2 as INTERNET_BUFFERS_VB, brtn as long
    brtn = HttpSendRequestEx( ??, byval ttt, ttt2, ??,??)

    This should be the typical kind of calling.

    Ther are two types of APIs. Ones that fill in a structure, ones that pass a pointer to structure.
    For those that fill in a structure, make sure that enough memory is available for all the items in the struct.
    For those that pass a pointer to a structure, typically in VC, they typecase the pointer and use it directly. SInce VB has no typecast facility, people usually copy the structure to a local variable of same type. For this use this fn:
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
    I dont know which is your case.


    RK

  4. #4

    Re: type conversion

    perfect ravi. you said it right. now i am dealing with the copy memory function and i am not sure how to pass the 3rd argument, ie the number of bytes to copy.

    do you know how to dereference the pointer back to my structure? basically as we do typecasting in c. i want to something like this in VB..

    mytype A = *(pointerToA);


    Here is the VB declarations for the API discussed here.

    Declare Sub CopyMemory1 Lib "kernel32" Alias "RtlMoveMemory" ( _
    hpvDest as Any, byval hpvSource as Long, byval cbCopy as Long)
    Declare Sub CopyMemory2 Lib "kernel32" Alias "RtlMoveMemory" ( _
    hpvDest as Long, hpvSource as Any, byval cbCopy as Long)
    public Type INTERNET_BUFFERS
    dwStructSize as Long ' used for API versioning. set to sizeof(INTERNET_BUFFERS)
    next as Long ' INTERNET_BUFFERS chain of buffers
    lpcszHeader as Long ' pointer to headers (may be null)
    dwHeadersLength as Long ' length of headers if not null
    dwHeadersTotal as Long ' size of headers if not enough buffer
    lpvBuffer as Long ' pointer to data buffer (may be null)
    dwBufferLength as Long ' length of data buffer if not null
    dwBufferTotal as Long ' total size of chunk, or content-length if not chunked
    dwOffsetLow as Long ' used for read-ranges (only used in HttpSendRequest2)
    dwOffsetHigh as Long
    End Type

    public Declare Function HttpSendRequestEx Lib "wininet.dll" Alias "HttpSendRequestExA" _
    (byval hHttpRequest as Long, lpBuffersIn as INTERNET_BUFFERS, byval lpBuffersOut as Long, _
    byval dwFlags as Long, byval dwContext as Long) as Long







  5. #5
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: type conversion

    Taking your example of HttpSendRequestEx, I dont know if this fn fills in the value of *Next field. Atleast the name suggests that you need to pass the pointer to a structure. So, first check that out]

    Also my definition of CopyMemory (RtlMoveMemory) is defined with both memory pointers as Any
    Though it is possible to play around with fn defitions, it is dangerous, unless you really know what VB thinks of your fn is same as what you want VB to think!!.

    In yours, in both definitions either one of them is defined 'Long'. So i will go with that (both 'any') definitaion i sent in the first post.

    Dim Ibuf1 as Internet_Buffers, Ibuf2 as Internet_Buffers

    if you want the Ibuf2 = lBuf1.Next in VB, do it like this:


    copymemory Ibuf2, byval Ibuf1.next, len(Ibuf2)




    Byval identifier at calling line, like above, indicates that, the value passed is to be copied (value), but the difinition says, it is actually the address (pointer), which is correct in our case, because what we are passing is a pointer.

    For this sturcture things are not finished yet. There are other memory pointers too in that.
    To copy the lpcszHeader, if not null, define a byte array of appropriate size and copy into it:

    dim tmpbuf() as byte
    ' after copying the info into IBuf2 structure as above
    if IBuf2.lpcszHeader <> &H0& then
    redim tmpbuf(Ibuf2.dwHeadersLength)
    copymemory tmpbuf,byval IBuf2.lpczHeader, Ibuf2.dwHeadersLength
    end if




    IDK, how much this helps you!:-)

    RK

  6. #6

    Re: type conversion

    I am having a tough time populating the INTERNET_BUFFERS structure used by the HttpSendRequestEx function. No documentation is available for this method. I know microsoft did not want us to use this method in VB but why cant they give us some documentation on this?

    I guess this is the pain working with microsoft technologies.

    anyone have any example of using HttpSendRequestEx and HttpEndRequest?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured