Solved

add function to Compiled exe

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now