CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: .exe to .dll?

  1. #1
    Join Date
    Dec 2008
    Posts
    9

    .exe to .dll?

    Hello,

    I'm fairly new to C++, still learning the ropes. I am using Visual Studio 2008 and I have a Visual C++ application that right now builds as a .exe and I'd like to see if I can have it build as a .dll. The reason being, I would like to access several functions within this application from a C# application and I read that this was a possible solution. I'd like to avoid re-writing them in C#.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2010
    Posts
    172

    Talking Re: .exe to .dll?

    If you wish to link a exe to a dll you would have to include the .dll its .lib and header;

    example of the dll header:

    Code:
    #ifndef DLLHEADER_H_INCLUDED
    #define DLLHEADER1_H_INCLUDED
    
    #ifdef DLL_EXPORT
    # define EXPORT __declspec (dllexport)
    #else
    # define EXPORT
    #endif
    
    extern EXPORT void Dll1 ();
    
    
    
    
    #endif
    Then the dll.cpp

    Code:
    #include "stdafx.h"
    #include <iostream>
    #define DLL_EXPORT//* define the export and import fuction
    
    #include "Dll.h"
    
    EXPORT void Dll1 () {
    
    //*What ever your code is 
    	
    }
    After you have built your dll. place the .lib .dll and its header in the .exe source folder then add the header like so to your .exe:
    Code:
    #include "Dll.h"
    Then for the exe you type in Dll1();
    like so:

    Code:
    #include "stdafx.h"
    #include "windows.h"
    #include "Dll.h"
    
    
    
    
    using namespace std;
    
    
    
    int _tmain()
    {
    
    		
    			Dll1 ();
    
    return 0;
    }
    this will then work with your dll
    Last edited by gaar321; July 19th, 2010 at 12:22 PM.

  3. #3
    Join Date
    Apr 2010
    Posts
    172

    Exclamation Re: .exe to .dll?

    If you do not wish to rewrite the code out again (which is lazy as it can be good practice) you can get a csharp to c++ converter vise versa

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

    Re: .exe to .dll?

    and exe and a dll are different Project types. You'll need to create a DLL project and copy the relevant code into the DLL.

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

    Re: .exe to .dll?

    Quote Originally Posted by gaar321 View Post
    If you do not wish to rewrite the code out again (which is lazy as it can be good practice) you can get a csharp to c++ converter vise versa
    Are you saying he's lazy for not wanting to rewrite existing code?

  6. #6
    Join Date
    Apr 2010
    Posts
    172

    Angry Re: .exe to .dll?

    I am only encourageing for people to learn carm down

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

    Re: .exe to .dll?

    Quote Originally Posted by gaar321 View Post
    I am only encourageing for people to learn carm down
    That doesn't make any sense.

  8. #8
    Join Date
    Apr 2010
    Posts
    172

    Unhappy Re: .exe to .dll?

    I was using a sarcastic approach by saying your lazy in other words motivate your self

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