Solved

add function to Compiled exe

Posted on 2006-07-08
5
279 Views
Last Modified: 2008-03-10
hi
can show me a source code for add a function from a Dll into a Compiled exe?
0
Comment
Question by:mahdiparak
5 Comments
 
LVL 4

Expert Comment

by:e_tadeu
ID: 17064723
Do you have the source code for this exe?
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17065086
If the exe is compiled, it's very, very difficult to change it. Doing so requires use of assembly language, where you patch existing code to call your new segment, and this has to be loaded correctly and the error-checking has to manage it too.

If you have the source code, it's easy enough, but I don't think that's the case here.

Why do you want to do this? If you explain your requirements more fully, we may be able to provide a reasonable solution.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17065234
>> can show me a source code for add a function from a Dll into a Compiled exe?
Are you trying to ask something else ?
0
 
LVL 4

Accepted Solution

by:
bdunz19 earned 500 total points
ID: 17073645
If I understand you correctly, you are looking to import a dll function into your exe at runtime?
If so you can load the dll using the following code which I have implemented in one of my own projects. You need to know the parameters of the funciton you are calling to make this work.

// The function in my dll that I want to use is defined as:
// BOOL GetPage(char *lpszHtml, CDC *pDC, CDC *pWndDC, CRect *pPageRect, int *pPageNumber, int *pTotalPages, bool bPrint);

// So here I create a type that has the same parameters as the one in my dll:
// (HTML2DC_GetPage is an arbitrary value I used to name my funciton pointer)
typedef BOOL (*HTML2DC_GetPage)(char *, CDC *, CDC *, CRect *, int *, int *, bool);

// Then I define a function pointer to that dll exported function
HTML2DC_GetPage GetPage;

// Load the dll
HINSTANCE hMod = LoadLibrary("renderhtml.dll");
if(hMod == NULL)
{
     return;
}

// Get a pointer to the dll function
GetPage = (HTML2DC_GetPage)GetProcAddress(hMod, "GetPage");
if(GetPage == NULL)
{
     FreeLibrary(hMod);
     return;
}

// Now call it as if this function is defined localy in my exe:
// (The parameters used are defined locally in my exe)
GetPage(lspzhtml_detail, &testDC, m_hdcPrn, &rDetail, &page, &total, true);


// All done so free the dll:
FreeLibrary(hMod);


I hope this helps. Let me know If you have any questions,
Brandon
0
 
LVL 4

Expert Comment

by:bdunz19
ID: 17073667
For more detailed information on this subject refer to this web page:

http://en.wikipedia.org/wiki/Dynamic_link_library

Regards,
Brandon
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question