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
Solved

VC++ Calling DLL function

Posted on 1997-12-19
8
733 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:quekky
ID: 1176759
can you print line 60 to 70 of this header file here
0
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

837 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