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


Followup DLL Question for all Wizards and Nietod

Posted on 1998-02-11
Medium Priority
Last Modified: 2013-12-03
To Nietod and all other Wizards:

I appreciate the assistance so far.
In working with the example given to me by nietod, I compiled the DLL example (with certain words that had to be capitalized) under MS VC++(Non IDE environment) and tried to test it under MS VB-V4.0 with no such luck.  What am I doing wrong?  Can you first test out the answer/solution to insure the solution is correct?   As for the number of points, you be the honest judge of that.

  Here is the example given and my make file, and what my environment is - that I use.

 I hope this helps.

 Email: methorpe@burgoyne.com

 Added NOTE:  I use the Microsoft Maintainance programming Utility, I believe it's called,  rather than the IDE environment - because it is easier to use.  Can you suggest any suggestions on how the MS VC++ IDE could and can be better.  I have a somewhat of the idea on how to set up the DLL environmental workspace within the VC++ IDE.  What I am trying or rather attempting to do, is to make a DLL like Microsoft has done and make the DLL very generic in nature(like the examples used under MS VB), which can be used under any Windows application platforms.  Which can pass data( character, and numerical(by reference or by value)) to and from DLL "C" routines.

 In going to Expert-Exchange for help, I was referred to you by a programmer, because he has had great success in getting answers to their questions.  "No such Luck" means, VB returns an 'illegal error message' as a result of calling and/or returning from the DLL routine, or when trying to correct the error, I get a error saying routine not found - Even though the declarations in the DLL file and the declarations in MS VB match exactly.  Also, with running under different windows platforms, what are the universal data types.  From talking with people, who only drop hints - they say the data types in MS VB do not correctly match up.
Any suggestions?  It seems like I can get into the DLL routine, but when exiting from the routine - there are problems that happens that I have no clue of what is going on.   These errors, could be from a range of problems. Such as: 1) Improper Function declaration.
    2) Improper Function parameter declaration, with regards          to correct data type declaration.
    3) And maybe mismatch datatypes and
        returning/exiting from a function/procedure.
   Test the example out.

  Midnightexpress,  thanks.

 Can you help??
** Here is the example that was given.

// #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#define DllImp __declspec(dllimport)
#define DllExp __declspec(dllexport)

 DllExp int Increment(int i);

    switch (Rsn) {
       case DLL_THREAD_ATTACH:
       case DLL_THREAD_DETACH:
    return TRUE; // always return true!

 DllExp int Increment(int i) {
    return i + 1;
# try1.MAK make file   <---- the make file.

#-- the try1 program set
try1.dll : try1.obj
     $(LINKER) $(DLLFLAGS) -OUT:try1.dll try1.obj $(GUILIBS) /map:dllout.map

try1.obj : try1.c
     $(CC) $(CFLAGSMT) try1.c   | more

-------------MY Environment for MS VC++
@echo off
rem Root of Visual C++ installed files.
rem     Note: This batch file will not work on Windows NT if MSDevDir contains spaces.
set MSDevDir=C:\MSDEV

rem Root of Visual C++ files on cd-rom.
rem Remove "set vcsource=" if you don't want include cdrom in Visual C++ environment.
set vcsource=E:\MSDEV

rem VcOsDir is used to help create either a Windows 95 or Windows NT specific path.
set VcOsDir=WIN95
if "%OS%" == "Windows_NT" set VcOsDir=WINNT

if "%1" == "x86" goto x86
if "%1" == "m68k" goto m68k
if "%1" == "mppc" goto mppc

echo Usage: vcvars32 [target]
echo     Where target is one of the following: x86, m68k, mppc.
if "%1" == "" goto default
goto done

echo No target specified.  Selecting x86 as default target.

echo Setting environment for building x86 target
if "%vcsource%" == "" goto x86main
rem Include cdrom files in environment.
if "%OS%" == "Windows_NT" set PATH=%vcsource%\BIN;%vcsource%\BIN\%VcOsDir%;%PATH%
if "%OS%" == "" set PATH="%vcsource%\BIN";"%vcsource%\BIN\%VcOsDir%";"%PATH%"
set INCLUDE=%vcsource%\INCLUDE;%vcsource%\MFC\INCLUDE;%INCLUDE%
set LIB=%vcsource%\LIB;%vcsource%\MFC\LIB;%LIB%
set vcsource=

if "%OS%" == "Windows_NT" set PATH=%MSDevDir%\BIN;%MSDevDir%\BIN\%VcOsDir%;%PATH%
if "%OS%" == "" set PATH="%MSDevDir%\BIN";"%MSDevDir%\BIN\%VcOsDir%";"%PATH%"
set LIB=%MSDevDir%\LIB;%MSDevDir%\MFC\LIB;%LIB%
goto done

echo Setting environment for building m68k target
if "%OS%" == "Windows_NT" set PATH=%MSDevDir%\mac\m68k\bin;%MSDevDir%\mac\bin;%MSDevDir%\BIN;%MSDevDir%\BIN\%VcOsDir%;%PATH%
if "%OS%" == "" set PATH="%MSDevDir%\mac\m68k\bin";"%MSDevDir%\mac\bin";"%MSDevDir%\BIN";"%MSDevDir%\BIN\%VcOsDir%";"%PATH%"
set INCLUDE=%MSDevDir%\mac\include;%MSDevDir%\mac\include\macos;%MSDevDir%\mac\include\mrc;%MSDevDir%\INCLUDE;%MSDevDir%\MFC\INCLUDE;%INCLUDE%
set LIB=%MSDevDir%\mac\m68k\lib;%MSDevDir%\LIB;%MSDevDir%\MFC\LIB;%LIB%
goto done

echo Setting environment for building mppc target
if "%OS%" == "Windows_NT" set PATH=%MSDevDir%\mac\mppc\bin;%MSDevDir%\mac\bin;%MSDevDir%\BIN;%MSDevDir%\BIN\%VcOsDir%;%PATH%
if "%OS%" == "" set PATH="%MSDevDir%\mac\mppc\bin";"%MSDevDir%\mac\bin";"%MSDevDir%\BIN";"%MSDevDir%\BIN\%VcOsDir%";"%PATH%"
set INCLUDE=%MSDevDir%\mac\include;%MSDevDir%\mac\include\macos;%MSDevDir%\mac\include\sys;%MSDevDir%\mac\include\mrc;%MSDevDir%\INCLUDE;%MSDevDir%\MFC\INCLUDE;%INCLUDE%
set LIB=%MSDevDir%\mac\mppc\lib;%MSDevDir%\LIB;%MSDevDir%\MFC\LIB;%LIB%

set VcOsDir=
REM -------------------------------------------------------------
REM  MSC.BAT -- Set up environment for Microsoft C/C++ 7.0 NMAKE
REM -------------------------------------------------------------
SET CFLAGS=-c -DSTRICT -G3 -Ow -W3 -Zp -Tp
SET GUILIBS=-DEFAULTLIB:user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
Question by:midnightexpress
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
  • 7
  • 3
LVL 22

Expert Comment

ID: 1411165
You said you had "no luck", but could you be more specific.  What is the problem?
LVL 22

Expert Comment

ID: 1411166
Is there a reason you are using make files?  Using the VC deveopment environment is much easier.

Author Comment

ID: 1411167
Edited text of question
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.


Author Comment

ID: 1411168
Edited text of question

Author Comment

ID: 1411169
Edited text of question
LVL 22

Expert Comment

ID: 1411170
I still don't see a discription of your problem.  

But lets try to get this working within VC's environment, rather than a make file.

You want a project that makes the Dll.
From the "file" menu go to "new..." option.
In the dialog box go to the "Projects" tab.
Choose "Win32 Dynamic link library" from the list.
Give the project a name like "TstDll"
Give it a path for you source and associated files, like "C:\TSTDLL"  (It will create this directory and some sub-directories of it.)
Make sure that "create new workspace" is selected.
Hit okay.

Then you'll have an empty workspace.
You need to add the source code file to the workspace.
Since it already exists, copy it into the directory used for the project.
Go to "Project" menu and select "add to Project"
Select "files" and choose the dll source code files.

Now you should be able to build it using the build option under the "build" menu.

Try this and let me know what's going on.

LVL 22

Expert Comment

ID: 1411171
Allright, I didn't know (or remember) that basic was involved.
The first problem is name decoration.  C++ actually produced a function with a different name than what you specify.  This is to handle overloading.  Basic doesn't know about this so it is looking for the wrong name.
LVL 22

Accepted Solution

nietod earned 0 total points
ID: 1411172
To fix this tell C++ not to decorate the name using the extern "C" directive like

DllExp extern "C" int Increment(int i) {
   return i + 1;

that will probably fix the problem where VB can't find the function.  

As for you other problem with "data not matching up", I can't help too much there.  The idea is that the VB side needs to declare parameters/return values that match the C++ side.  I don't know basic types, but in VC an "int" is 32 bits (4 bytes), a "short" is 16 bits (2 bytes), a "char" is one byte (no shock there).  They are all signed by default.  Althoug you don't really need to work about signed/unsigned too much.  

Also the parameters are passed in reversed order.  So if you declare

void F(int i,char ch)

The character is pushed first and then the integer.  make sure the basic side declares things so they are pushed in the order that C++ expects.

LVL 22

Expert Comment

ID: 1411173
If you need more help, could you do me a favor and edit the question one more time and put some line breaks in.  I don't know why, but for some reason when I view your question it consists of very long lones that don't wrap.  I've never seen it do that before and it makes it very hard to read.  I may have missed important parts of you explanation because of it.  
LVL 22

Expert Comment

ID: 1411174
I didn't really solve your problems with my answer, but you did accept it.  Does that mean you've got it working?

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

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