Solved

VC++ Calling DLL function

Posted on 1997-12-19
8
731 Views
Last Modified: 2012-05-04
I want to write a vc++ program that can call external DLL functions. Does anyone know how to do that? Thanks in advance.
0
Comment
Question by:softyan
8 Comments
 
LVL 1

Expert Comment

by:quekky
ID: 1176756
do you have the header file and library of this dll?
if you have, just add the library to your project

0
 
LVL 1

Expert Comment

by:quekky
ID: 1176757
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
 

Author Comment

by:softyan
ID: 1176758
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
 
LVL 1

Expert Comment

by:quekky
ID: 1176759
can you print line 60 to 70 of this header file here
0
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.

 

Author Comment

by:softyan
ID: 1176760
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
 
LVL 1

Expert Comment

by:quekky
ID: 1176761
try
#include <windows.h>
#include "odbcinst.h"
0
 

Expert Comment

by:XLogger
ID: 1176762
try this:

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

it helped me to resolve the same problem.
0
 

Accepted Solution

by:
yingchunli earned 100 total points
ID: 1176763
You might do it in the following way:

void (*PtrFunctionInDll)();
HINSTANCE hInstance;

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


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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

896 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

12 Experts available now in Live!

Get 1:1 Help Now