Results 1 to 12 of 12

Thread: C .lib file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187

    C .lib file

    Hi, yesterday I was browsing the net and found this code in C written by Microsoft. It is code to decompress .bgl files for Microsoft Flight Simulator 2000. I do not know C, however, and am not sure how the code below would translate to VB. Can anyone help?

    Code:
    /***
     * bglzip.h - definitions for bgl file decompression
     *
     *       Copyright (c) 1999, Microsoft Corporation. All rights reserved.
     *
     ****/
    
    #ifndef _bglzip_h_
    #define _bglzip_h_
    
    /*****
     *
     * ERROR CODES
     *
     *****/
    
    /*
     * BGLZIP_OK 
     * The operation completed successfully.
     */
    #define BGLZIP_OK                  0x00000000
    
    /*
     * BGLZIP_BADARGS 
     * Bad arguments were passed to the API.
     */
    #define BGLZIP_BADARGS             0x00000001
    
    /*
     * BGLZIP_NOTCOMPRESSED 
     * The file that the caller asked to be decompressed was not compressed.
     */
    #define BGLZIP_NOTCOMPRESSED       0x00000002
    
    /*
     * BGLZIP_OUTOFMEMORY 
     * The system ran out of memory during the requested operation.
     */
    #define BGLZIP_OUTOFMEMORY         0x00000004
    
    /*
     * BGLZIP_SIZEMISMATCH 
     * The decompression operation did not preserve the
     * original file length.
     */
    #define BGLZIP_SIZEMISMATCH        0x00000008
    
    /*
     * BGLZIP_BADCHECKSUM
     * The decompression failed to preserve the original file's checksum.
     */
    #define BGLZIP_BADCHECKSUM         0x00000010
    
    /*
     * BGLZIP_DECOMPRESSIONFAILED
     * The decompression algorithm failed abnormally.
     */
    #define BGLZIP_DECOMPRESSIONFAILED 0x00000020
    
    /*
     * BGLZIP_CANNOTOPENFILE
     * The requested file could not be opened.
     */
    #define BGLZIP_CANNOTOPENFILE      0x00000040
    
    /*****
     *
     * API Calls.  Win32 API calling convention.
     *
     *****/
    
    /*
     * FSGetUncompressedBGLData(...)
     *
     * Decompress a compressed BGL file.
     *
     * Arguments:
     *
     *   szFileName - Name of the file to be decompressed.
     *   pdwSize    - Pointer to a DWORD that will be filled in with the size
     *                of the decompressed data.
     *   ppData     - Pointer to a PVOID that will be filled in with a pointer
     *                to the decompressed data.
     *
     * After successfully calling this API and extracting the requested data,
     * FSCompleteBGLOperation(...) *must* be called to free up allocated resources.
     *
     */
    DWORD WINAPI FSGetUncompressedBGLData(LPCSTR szFileName,
    									  DWORD* pdwSize,
    									  PVOID* ppData);
    
    /*
     * FSCompleteBGLOperation(...)
     *
     * Free up resources allocated by FSGetUncompressedBGLData(...).
     *
     * Arguments:
     *
     *   dwSize     - The size of the data as given by the call to
     *                FSGetUncompressedBGLData(...).
     *   pData      - The pointer to the uncompressed data as given by the call to
     *                FSGetUncompressedBGLData(...).
     *
     */
    
    DWORD WINAPI FSCompleteBGLOperation(DWORD dwSize,
    									PVOID pData);
    
    #endif /* _bglzip_h_ */

    Along with the file above is a file called bglzip.lib, which contains the functions. I can post it if it is needed. How can these API calls be translated to VB?

    Thanks,
    Allen
    - Visual Basic 6.0
    - Windows XP Home

  2. #2
    The header file is useless unless you have the .lib file. And .lib will only decompile to assembly.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187
    But I do have the .lib file. (and it looks like senseless junk when opened in Notepad). And it will do exactly what I want, decompile the files to their original form. Microsoft provided it for that purpose.

    Look at the line below:
    DWORD WINAPI FSGetUncompressedBGLData(LPCSTR szFileName, DWORD* pdwSize, PVOID* ppData);

    This is pretty clearly an API declaration. I'm guessing the VB version would be something like this:

    Private Declare Function FSGetUncompressedBGLData Lib "bglzip.lib" Alias "FSGetUncompressedBGLData" (ByVal szFileName As String, ???????) As Long

    I get lost at the question marks. I presume that once the bglzip.lib file in in the System directory I can call it via the API, but I don't know what needs to go after the question marks. Any help?

    - Allen
    - Visual Basic 6.0
    - Windows XP Home

  4. #4
    Zaei
    Guest
    "Private Declare Function FSGetUncompressedBGLData Lib "bglzip.lib" Alias "FSGetUncompressedBGLData" (ByVal szFileName As String, ByRef pdwSize as long, ByRef pdwData as Long) As Long".

    It would be called like so:
    Code:
    retval = FSGetUncompressedBGLData("c:\somefile.ext", size, data(0))
    At this point, the array "data()" will be filled with the uncompressed data.

    Z.

  5. #5
    Zaei
    Guest
    Oh, and i think you need the actual bglzip.dll. The Declare filename should be "bglzip.dll".

    Z.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187
    OK, I don't have a DLL, just a .lib file. Can the .lib file be made into a DLL?

    Here is the site I got this all from:
    http://www.microsoft.com/games/fs2000/articles_BGL.asp

    It is the thing at the bottom where it says: "This file (BGLIB.EXE) is a developers-only code library for decompressing BGL files within 3rd party applications. This is a companion to the previously released BGLINST.EXE."

    All I want to do is use that in my VB application.

    Thanks for your help,

    - Allen
    - Visual Basic 6.0
    - Windows XP Home

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Post

    No, you can't. The .lib file is a static library (as opposed to the dll, a Dynamic Link Library), which means that it is precompiled code to be inserted in a C/C++ program by the linker.
    Therefore it is not possible to directly create a DLL for it. You can however, build a wrapper DLL if you have VC++, which would look something like this:
    PHP Code:
    DWORD __stdcall WrapperFunc(LPCSTR szFileNameDWORD
                                                       
    pdwSizePVOIDppData)
    {
        return 
    FSGetUncompressedBGLData(szFileNamepdwSize
                                                                  
    ppData); 
    But be warned, I had serious difficulties using OUT-pointers ( that receive data), so it might be necessary that you only supply the filename to the wrapper function, which in turn gets the data and saves it to a file, which you can later open in VB.
    In this case, the function would look like this:
    PHP Code:
    DWORD __stdcall WrapperFunc(LPCTSTR szFileName)
    {
         
    HANDLE hFile;
         
    DWORD dwResult;
         
    PVOID pData;
         
    DWORD dwSize;
         
    dwResult FSGetUncompressedBGLData(szFileName, &dwSize, &pData);
         if(
    dwResult == /* positive result */)
              
    /* Save content of pData to a file */
         
    return dwResult;

    In vB you could then either load the file and do something with it, or you could just say that the decompression was successful and use the data directly with some editors.

    Have Fun
    CornedBee

    P.S. refer to the many other posts for information about using dlls in vB. Especially those from parksie

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187
    Thanks for your reply, CornedBee. I do not have VC++ and know nothing at all about C or C++. And I looked for stuff from parksie, but it doesn't make sense to me since I don't know C++.

    What I want to do is save the data to a file just like you said in your second example, say, "Data.txt" It looks that code you put there is just about what I would need.

    This might be asking too much, but would it be possible for someone who has C++ to compile it with the lib file and send it to me so that all I would just have to call the C++ exe from VB with a filename as the command line and it would uncompile the file passed and save it to "App.Path\Data.txt" ? It looks like you basically have all the code right there, but if it is too much trouble, I understand.... Boy, I wish Microsoft would have had a VB version of their code....

    - Allen
    [email protected]
    - Visual Basic 6.0
    - Windows XP Home

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187
    Also, in case anyone wants one of the files to be uncompressed to test it on, I've attached one to this message. (It is zipped.)
    Attached Files Attached Files
    - Visual Basic 6.0
    - Windows XP Home

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Ok, I did it

    This is one thing that is supposed to work, but I guarantee nothing!
    declare it like this:

    Code:
    private declare function GetUncompressedData 
    lib "PATH_TO_DLL\bgldll.dll" (ByVal path_and_name_of_source_file as string, ByVal path_and_name_of_target_file as string) as long
    return value is one of those mentioned in bglzip.h, the targetfile is always emptied! After the operation it contains pure binary data (exactly what pData contained). You have to figure out yourself how to use it.
    I tested a the dll a little bit with my own c++ program, but i got very confused, and i couldn't test the latest version, so i hope this one works.

    Have fun
    CornedBee

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    forgot to link the file
    Attached Files Attached Files

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187

    Talking

    Thanks a lot - I haven't had time to fiddle with it yet, but it looks like exactly what I need....

    Thanks heaps for your time.

    - Allen
    - Visual Basic 6.0
    - Windows XP Home

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