Solved

add function to Compiled exe

Posted on 2006-07-08
5
260 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
Comment Utility
Do you have the source code for this exe?
0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

744 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

15 Experts available now in Live!

Get 1:1 Help Now