Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 738
  • Last Modified:

VC++ Calling DLL function

I want to write a vc++ program that can call external DLL functions. Does anyone know how to do that? Thanks in advance.
0
softyan
Asked:
softyan
1 Solution
 
quekkyCommented:
do you have the header file and library of this dll?
if you have, just add the library to your project

0
 
quekkyCommented:
if not, you can use:-

HINSTANCE LoadLibrary(
  LPCTSTR lpLibFileName  // address of filename of executable module
);
 
FARPROC GetProcAddress(
  HMODULE hModule,  // handle to DLL module
  LPCSTR lpProcName  // name of function
);


if the dll is your own, you can create dependencies in VC

0
 
softyanAuthor Commented:
I do have the header file of the dll, but i don't have the library of this dll. I included the header file in my program, like the following:

#include <odbcinst.h>

but everytime i compile the program it give me this kind of error:

C:\MSDEV\INCLUDE\odbcinst.h(67) : error C2143: syntax error : missing '{' before '__stdcall'
C:\MSDEV\INCLUDE\odbcinst.h(67) : error C2146: syntax error : missing ')' before identifier 'hwndParent'
C:\MSDEV\INCLUDE\odbcinst.h(67) : error C2501: 'hwndParent' : missing decl-specifiers

i don't know what's going on about this header file, i checked it with other header file, but there are similar to each other!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
quekkyCommented:
can you print line 60 to 70 of this header file here
0
 
softyanAuthor Commented:
Here is the header file, thanks in advance for helping me!

#ifndef WIN32
#define SQLGetPrivateProfileString   GetPrivateProfileString
#define SQLWritePrivateProfileString WritePrivateProfileString
#endif

// High level APIs
BOOL INSTAPI SQLInstallODBC          (HWND       hwndParent,
                                      LPCSTR     lpszInfFile,
                                                        LPCSTR     lpszSrcPath,
                                                        LPCSTR     lpszDrivers);

0
 
quekkyCommented:
try
#include <windows.h>
#include "odbcinst.h"
0
 
XLoggerCommented:
try this:

  extern "C" {
  #include "odbcinst.h"
  }

it helped me to resolve the same problem.
0
 
yingchunliCommented:
You might do it in the following way:

void (*PtrFunctionInDll)();
HINSTANCE hInstance;

hInstance=::LoadModule("yourDll.DLL");
PtrFunctionInDll=::GetProcAddress(hInstance, "functionInDll");


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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now