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

x
?
Solved

VC++: Weird problem with DLLs

Posted on 1998-02-16
3
Medium Priority
?
194 Views
Last Modified: 2010-04-10
I am trying to figure out how to use other peoples' DLLs in Visual C++, but for some reason I can't seem to load the DLL into memory. I tried the following:

Created a new MFC application (.exe) and added the following code fragment anywhere (for example in CTestView::OnDraw):

HINSTANCE hlib = AfxLoadLibrary("commdlg.dll");
DWORD error = GetLastError();

When I step through this code I see that hlib obtains the value 0 (load failure) and error is equal to 31, which is the error code for General Failure Error. What in the world does a general failure error have to do with loading a DLL? The same result occurs regardless of the DLL I am using (I used commdlg.dll because I know it's a DLL that works). I know that error 31 is originating from AfxLoadLibrary because when I use GetLastError before the call to AfxLoadLibrary I get an error code 0 (success).

What is going on here? I doubt the General Failure error is really what's going on because everything in my OS is working properly (including things that other programs load from the commdlg.dll library). How can I solve this problem?
(Please don't tell me that I can use MFC functions that call commdlg.dll. I've already tried it, and it works. That library name is only an example. The same result happens no matter what DLL I try to load, this is just so that you can try the above code fragment on your computer if you want).

Thanks in advance!

-- Slarti
0
Comment
Question by:Slarti
[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
3 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 100 total points
ID: 1182344
I guess you mistake is that you trying to load commdlg.dll which is 16 bit DLL into 32 address space of your EXE. try to load 32 bit version of this DLL comdlg32.dll
0
 
LVL 2

Author Comment

by:Slarti
ID: 1182345
That is probably the problem, then. But I would still like to be able to load 16-bit DLLs into memory. (The problem is that I am trying to interface with a device driver written for Windows 3.1). How can I load a 16-bit DLL?
0
 

Expert Comment

by:donleyp
ID: 1182346
You cannot load a Win16 DLL into a Win32 program's address space. Win32s provided a way for you to do this, but I don't know if it's even supported anymore. Furthermore, Trying to interface to a Win16 device driver in a Win32 environment is extremely dangerous if not impossible. How can you interface to it if the OS won't even load it? Even if you wrote a Win16 program and loaded the driver file directly, Windows would prevent you from accessing the device without going through bona-fide drivers.
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

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…
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. …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

618 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