[RESOLVED] Add header files & lib files at runtime?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Thread: [RESOLVED] Add header files & lib files at runtime?

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    [RESOLVED] Add header files & lib files at runtime?

    Hi,

    I was created a dynamic library (Used win32 App) & compiled with no error.

    Then i was created my main application (MFC) & paste the .h,.lib,.dll files from the source path(dll App Path) to destination path(Main App Path).
    If i used the below command in my app means the project working good.

    Code:
    #include "Alg.h"
    #Progma Command(lib, "VTAlg.lib")
    & also paste the VTAlg.dll in my app path.

    here Alg.h contains the some methods , In future i will edit the function like below for my client requirement but no function name & Arguments change. The changes made in inside function(Logically changed) only.

    My client contains only .exe file + .dll file.

    My requirement,

    So after change the method i will send only .dll file to my client

    If i change my lib file name VTAlg2.lib instead of VTAlg1.lib (But Same Function name & Arg type)means how can i edit the code below

    Code:
    #include "Alg.h"
    #Progma Command(lib, "VTAlg.lib")
    & How to run my application at client place.

    Pls Clear me is possible?
    Regards,

    SaraswathiSrinath

  2. #2
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by saraswathisrinath View Post
    & How to run my application at client place.
    A header and .lib files have nothing to do with running the final executable. They only are used when building your application.

    Similarly, a DLL has nothing to do when building your application -- a DLL only is used when you're running your application.

    So I have no idea what you're asking. You build your application, then you install the EXE's and DLL's at the client site, and you run the app at the client's site. Your source code or lib files have absolutely no part in running the final application.

    Regards,

    Paul McKenzie

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: Add header files & lib files at runtime?

    Instead of using a header file and lib file, use LoadLibrary and GetProcAddress to call your DLL function. Then you can just distribute the DLL without having to rebuild the client app.

  4. #4
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: Add header files & lib files at runtime?

    Can you send any example.... B'cos I'm in learning stage only.
    Regards,

    SaraswathiSrinath

  5. #5
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: Add header files & lib files at runtime?

    Hi Mr.GCDEF,

    I used LoadLibrary and GetProcAddress to call my DLL function, working good.

    I referred the below site:

    DLL Tutorial For Beginners

    Thanks a lot once again.
    Regards,

    SaraswathiSrinath

  6. #6
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: Add header files & lib files at runtime?

    Hi,

    OK fine. But my doubt is

    If I change the dll name & lib name ? Header file is same.

    First I'm used add.h, Alg1.lib & Alg1.dll files & prepared MyApp.exe, after changed made in logic, I'm having add.h, Alg2.lib & Alg2.dll. Now how can I run my application?

    Code:
    For Example - Alg1.dll logic : 
    
    int add(int a,int b)
    { 
    return a+b;
    }
    
    In Future, I will change the logic like below, Alg2.dll - logic :
    
    int add(int a ,int b)
    {
     return a+b + 100;
    }
    That is, I given the MyApp.exe & Alg1.dll to my client .

    For avoid confusion, After changes made, I'm changed the name like Alg2.dll.


    Now how can i run my application.

    At this time how can I import & include the library & header files.
    Regards,

    SaraswathiSrinath

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by saraswathisrinath View Post
    Hi,

    OK fine. But my doubt is

    If I change the dll name & lib name ? Header file is same.

    First I'm used add.h, Alg1.lib & Alg1.dll files & prepared MyApp.exe, after changed made in logic, I'm having add.h, Alg2.lib & Alg2.dll. Now how can I run my application?

    Code:
    For Example - Alg1.dll logic : 
    
    int add(int a,int b)
    { 
    return a+b;
    }
    
    In Future, I will change the logic like below, Alg2.dll - logic :
    
    int add(int a ,int b)
    {
     return a+b + 100;
    }
    That is, I given the MyApp.exe & Alg1.dll to my client .

    For avoid confusion, After changes made, I'm changed the name like Alg2.dll.


    Now how can i run my application.

    At this time how can I import & include the library & header files.
    I don't know of a practical way to do that. What's the point in renaming your DLL?

  8. #8
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: Add header files & lib files at runtime?

    Hi GCDEF,

    I declare my function like DataProcess(int **InData, int width, int height, int **OutData);

    I did some logic using algorithm for some calculation using **InData 2D Array.

    In future, I found one more best algorithm means, just i will replace the logic using the 2D( **InData) array.

    For this I will get the best result in my application.

    If I change the dll name means its very convenient for my clients to replace the old one.

    Also, gives a hint to find the logic to me.
    Regards,

    SaraswathiSrinath

  9. #9
    Join Date
    Apr 1999
    Posts
    27,423

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by saraswathisrinath View Post
    If I change the dll name means its very convenient for my clients to replace the old one.
    How is that convenient? I now have to change my source code or whatever code I'm writing that uses the DLL to read a new name. That is not convenient, as it now puts my own code at risk because of the changes that I would need to make.

    You shouldn't be changing the name of the DLL. What you should be doing is ensuring that the current version of the DLL that is "good" is the one being loaded. And you do that by telling your clients "I have a later version of the DLL. Make sure you are loading version xxx.xxx of the DLL". Programmers who know how to use DLL's are perfectly capable of loading the correct version at runtime if you tell them that a later version is available.

    Regards,

    Paul McKenzie

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by saraswathisrinath View Post
    Hi GCDEF,

    I declare my function like DataProcess(int **InData, int width, int height, int **OutData);

    I did some logic using algorithm for some calculation using **InData 2D Array.

    In future, I found one more best algorithm means, just i will replace the logic using the 2D( **InData) array.

    For this I will get the best result in my application.

    If I change the dll name means its very convenient for my clients to replace the old one.

    Also, gives a hint to find the logic to me.
    I don't see how that's more convenient and it seems like a design flaw to me. I'd rethink your approach rather than chasing something that doesn't make sense. Other app builders don't do it that way, and there's a reason for it.

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by saraswathisrinath View Post
    If I change the dll name & lib name ? Header file is same.

    First I'm used add.h, Alg1.lib & Alg1.dll files & prepared MyApp.exe, after changed made in logic, I'm having add.h, Alg2.lib & Alg2.dll. Now how can I run my application?
    I cannot see anything here to doubt about. If you change .lib file, you have no option other than full rebuild of your .exe and .dll. The new .exe will know the new name of .dll by linking to the proper .lib. No matter what the name of header or lib was.
    Best regards,
    Igor

  12. #12
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,266

    Re: Add header files & lib files at runtime?

    To run your application if you really, really want to have the version number as part of the .dll name and you want to use the latest dll version and you are using LoadLibrary then a 'kludge' is to try to use LoadLibrary with a name which has a very high version number. Assuming this fails, then try LoadLibrary with a lower version etc etc until LoadLibrary succeeds. You then have loaded the latest version of the .dll. Something like

    Code:
    const string dllname = "Alg";
    
    char	num[10];
    
    int	maxver = 100;
    
    HMODULE	library;
    
    	do {
    		string name = dllname + _ltoa(maxver, num, 10) + ".dll";
    		library = LoadLibrary(name.c_str());
    	} while (maxver-- && (library == NULL));

  13. #13
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,931

    Re: Add header files & lib files at runtime?

    Well, I've downloaded the sources, built the binaries and found those working correct. I re-read the thread and failed to understand what or where your problem is. I can see some arguing about renaming dll, but I don't see the requirement explained clear. Too many words, and no definition. So please explain the situation with your requirement, and I'll be glad to comment on it.
    Best regards,
    Igor

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center