Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

add function to Compiled exe

Posted on 2006-07-08
5
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

609 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