pasting code form a .txt file...

This is a discussion on pasting code form a .txt file... within the C++ Programming forums, part of the General Programming Boards category; it is on No. Oh I'm screwed...and that dll.h replacement stilld on't work. I think I might need the extern ...

  1. #61
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    it is on No. Oh I'm screwed...and that dll.h replacement stilld on't work. I think I might need the extern c thing, But how do I do that?

  2. #62
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    ROFL I think I just figured out your problem...

    Hit ctrl+F0 to compile...

    I bet you did what I did and hit just F9.
    What is C++?

  3. #63
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    F9... run? As opposed to ctrl-F0 for build?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #64
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Yeah F9 is compile and run, ctrl + F9 is compile
    What is C++?

  5. #65
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Ok I got it to work.

    **dll.h**
    Code:
    #ifndef _DLL_H_
    #define _DLL_H_
    
    extern "C"
    
    #if BUILDING_DLL
    # define DLLIMPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */
    
    
    DLLIMPORT void test();
    
    
    #endif /* _DLL_H_ */
    **dllmain.cpp**
    Code:
    /* Replace "dll.h" with the name of your header */
    #include "dll.h"
    #include <iostream>
    
    DLLIMPORT void test()
    {
        
        std::cout << "Plug IN!";
        
    }
    And thats the plugin. And heres the program that uses it.

    Code:
    #include <windows.h>
    #include <iostream>
    
    int main()
    {
        
        void(*TextFunc)();
        
        HMODULE hMod = LoadLibrary("TestPlug.dll");
        
        if(!hMod) std::cout << "Error Loading DLL";
        
        else {
            
            TextFunc = (void(*)())GetProcAddress(hMod, "test");
            
            if(TextFunc) TextFunc();
                
            else std::cout << "Error Finding Function";    
            
        }      
            
        std::cin.get();
        return 0;    
        
    }
    What is C++?

  6. #66
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    You didnt have to prefix extern "C" to the function for it to work vicious?

  7. #67
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Nope.

    EDIT: Er, wait, I did include it in the dll.h, I forgot about that.

    I'll try it without it.

    lol, now I cant get it to work period.. jeez.

    EDIT2:

    Yeah ok, you need to put extern "C" for it to work. But I gusee you can just do it "Globally" and not per function. I tried it both ways.
    Last edited by Vicious; 09-09-2004 at 11:56 PM.
    What is C++?

  8. #68
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    try prefixing extern "C" to the function declarations and definitions.

  9. #69
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Ok, i'm foiled again...

    HERE is what works...

    You must put extern"C" before each function prototype.

    Here is more accurate code

    Code:
    #ifndef _DLL_H_
    #define _DLL_H_
    
    #if BUILDING_DLL
    # define DLLIMPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */
    
    
    extern "C" DLLIMPORT void Text();
    extern "C" DLLIMPORT void Text2();
    
    #endif /* _DLL_H_ */
    Code:
    #include "dll.h"
    #include <iostream>
    
    DLLIMPORT void Text()
    {
        
        std::cout << "Plug in";
        
    }
    
    DLLIMPORT void Text2()
    {
        
        std::cout << std::endl;
        
        std::cout << "ah";
        
    }
    On a side note, if your using Dev-C++ its a good idea to "Rebuild All" instead of just compilng it. (When you make changes to it).

    I have a feeling that trying to use classes would be very different.
    What is C++?

  10. #70
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>You must put extern"C" before each function prototype.
    Actually, there's supposed to be some way to find the compiler's mangled name for your function when you compile the .dll. Then instead of putting extern "c", you could use the mangled name in GetProcAddress() I guess you should probably stick to extern "c"... But come to think of it, you should probably just link the lib and screw manually loading the functions altogether.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  11. #71
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    lol wow you all did aot when I was at school. I'll try the code above and see if it works...for me...

  12. #72
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok I tired the code and well guess what!? It didn't work. I code must be right by now but the host file is screwing everything up...

    Ok first thing crtl + f9 didn't do anything mroe then hiting compile. I know for sure the host file is screwing everything up.

  13. #73
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Make SURE you compile and not compile and run the DLL.
    What is C++?

  14. #74
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    It takes a long to rebuild but I think I might have got it to work finally! If this does work then I will be the biggest idoit this week....

  15. #75
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Yeah, i'm used to hitting f9 to compile and run my programs. I did that same thing with the dll and just started laughing.
    What is C++?

Page 5 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  2. read from .txt file & put into array?
    By slow brain in forum C Programming
    Replies: 6
    Last Post: 02-25-2003, 05:16 AM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21