CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    [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,449

    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
    Location
    Florida
    Posts
    12,635

    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
    333

    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

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

    Re: Add header files & lib files at runtime?

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

    SaraswathiSrinath

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

    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

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

    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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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));

  9. #9
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    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

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    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

  11. #11
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  13. #13
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by Paul McKenzie View Post
    You shouldn't be changing the name of the DLL
    It one of my project requirement. Then How can i say no possible?

    But I'm not hot code the DLL Name In My project.

    Just Browse the dll from particular location & save the path in to a string then only i will load the DLL at run time.

    Quote Originally Posted by GCDEF View Post
    I don't see how that's more convenient and it seems like a design flaw to me.
    I'm sure, Myself only didn't clear you correctly.

    Quote Originally Posted by Igor Vartanov View Post
    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.
    But I just copied the 1st version of dll & lib files in to my main project header files location & then Build the mainapp.exe

    Here by i prepared sample .exe & .dll for your reference.

    Kindly find the attachment.

    I attached DLLExport.dll, DLLAlg1.dll & VTMain.exe.

    First load any dll using browse button & Click the CALC Button.

    The result will be display in message box.

    For example only i add 25 +45 = 70 & 25 + 75 + 100 = 170.

    But my logic is different.

    Pls clear me, If I'm going to wrong way?
    Attached Files Attached Files
    Regards,

    SaraswathiSrinath

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Add header files & lib files at runtime?

    Quote Originally Posted by saraswathisrinath View Post
    But I'm not hot code the DLL Name In My project.

    Just Browse the dll from particular location & save the path in to a string then only i will load the DLL at run time.

    I'm sure, Myself only didn't clear you correctly.

    But I just copied the 1st version of dll & lib files in to my main project header files location & then Build the mainapp.exe
    When loading DLL explicitly at runtime, you never need LIB file at compile time. So all your talks about LIB were definitely misguiding. If you want to get some real help, you have to learn explaining your problem clear, concise and unambiguously.

    As for the archives you uploaded, I never experiment with binaries which origins I'm uncertain of.
    Best regards,
    Igor

  15. #15
    Join Date
    Nov 2011
    Location
    India
    Posts
    333

    Re: Add header files & lib files at runtime?

    Sorry Mr.Igor Vartanov. Mistake is mine . I wrongly told you

    But I just copied the 1st version of dll & lib files in to my main project header files location

    Really sorry. I tried 3 type of solution for that only this confusion.

    Kindly find the source code.
    Attached Files Attached Files
    Regards,

    SaraswathiSrinath

Page 1 of 2 12 LastLast

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