Solved

add function to Compiled exe

Posted on 2006-07-08
5
284 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

792 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