CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    Binary Data File

    I'd like to pass a binary data file from component to client, can somebody help me how to implement it?

    Thanks.


  2. #2
    Guest

    Re: Binary Data File

    Make a SafeArray with VT_UI1.


  3. #3
    Join Date
    May 1999
    Posts
    12

    Re: Binary Data File

    Hi,
    You can add the desired binary file to your COM DLL as a resource file. This would be similar to adding bitmaps,icons,dialog boxes, etc. But in this case your file is a user defined resource type. Let us say "MyBINARY" . Once you have done this
    you can dump the bytes of this data file at run time, and store it as a file or pass it as an array of charcters to some other function.

    To get a pointer to a resource data do the following:

    /////////////////////////////////////////////////////////////////////////////
    HRSRC rc = FindResource(hDllInst,lpszResName,lpszResType);
    //here lpszResName is the name you have given to your binary resource,
    //eg: "BIN_DATA1"
    //lpszResType is the type of resource, "MyBINARY" in this case
    //the module instance handle is hDllInst

    if (rc == NULL ) return FALSE;

    HGLOBAL hglb=LoadResource(NULL,rc);
    if (NULL == hglb) return FALSE;

    LPVOID lpv=LockResource(hglb);
    if (lpv == NULL ) return NULL;
    //you have just got hold of the pointer to the first byte of the resource
    //Now you need to know the size

    DWORD size = SizeofResource(NULL,rc);
    /*
    Now you have what you want, you can pass the data buffer as an array of bytes along with the size of the array OR dump it to a binary file
    */
    /////////////////////////////////////////////////////////////////////////////
    Hope this solves your problem,

    Regards
    Saurabh



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