4 Replies - 353 Views - Last Post: 02 October 2012 - 02:46 AM Rate Topic: -----

#1 EmaPat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 12

Call function from library

Posted 01 October 2012 - 05:48 PM

Hello
I am programming an executable application (not a dll or any kind of library). I simply want an equivalent of calling function using GetProcAddress and not just a simple typedef because that method didn't seem to work for executable but only for dll developments. Here is a working example:

typedef HRESULT (*pCoInit)(LPVOID);
pCoInit CoInit = (pCoInit)GetProcAddress(LoadLibrary("ole32.dll"),"CoInitialize");


CoInit will be called instead of CoInitialize.

But when I try this code to generate an executable, when I double click the executable the program crashes. So I don't know if their is an alternative to GetProcAddress which can be used to build executable and not a dll.

Regards

Is This A Good Question/Topic? 0
  • +

Replies To: Call function from library

#2 EmaPat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 12

Re: Call function from library

Posted 01 October 2012 - 05:55 PM

Also I don't know if loadlibrary can be used to load from a static library rather than a dynamic one or no, example ole32.lib instead of ole32.a ?
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3172
  • View blog
  • Posts: 9,610
  • Joined: 05-May 12

Re: Call function from library

Posted 01 October 2012 - 07:04 PM

Did you attach a debugger to see where the crash was?

Was the crash due to GetProcAddress() failing and returning a null pointer, or was it something else that caused the crash?

Another thing to consider is that you need to make sure you have the appropriate decorations on your function pointer: e.g. WINAPI, OLEAPI, or whatever is in the header files.

This post has been edited by Skydiver: 01 October 2012 - 07:04 PM

Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,400
  • Joined: 19-February 09

Re: Call function from library

Posted 01 October 2012 - 07:54 PM

Are you wanting to use COM?

CoInitialize
Was This Post Helpful? 0
  • +
  • -

#5 EmaPat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 12

Re: Call function from library

Posted 02 October 2012 - 02:46 AM

Thank you both very mush for your help :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1