Link to home
Start Free TrialLog in
Avatar of midnightexpress
midnightexpressFlag for United States of America

asked on

Followup DLL Question for all Wizards and Nietod

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.

 Midnightexpress
 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);

BOOL WINAPI DllMain(HINSTANCE DLLHnd, ULONG Rsn, LPVOID Rsv) {
    switch (Rsn) {
       case DLL_PROCESS_ATTACH:
         break;
       case DLL_PROCESS_DETACH:
         break;
       case DLL_THREAD_ATTACH:
         break;
       case DLL_THREAD_DETACH:
         break;
    }
    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
rem Root of Visual C++ installed files.
rem     Note: This batch file will not work on Windows NT if MSDevDir contains spaces.
rem
set MSDevDir=C:\MSDEV

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

rem
rem VcOsDir is used to help create either a Windows 95 or Windows NT specific path.
rem
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

:default
echo No target specified.  Selecting x86 as default target.

:x86
rem
echo Setting environment for building x86 target
rem
if "%vcsource%" == "" goto x86main
rem
rem Include cdrom files in environment.
rem
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=

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

:m68k
rem
echo Setting environment for building m68k target
rem
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

:mppc
rem
echo Setting environment for building mppc target
rem
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%

:done
set VcOsDir=
-------
REM -------------------------------------------------------------
REM  MSC.BAT -- Set up environment for Microsoft C/C++ 7.0 NMAKE
REM -------------------------------------------------------------
SET CC=cl
SET CFLAGS=-c -DSTRICT -G3 -Ow -W3 -Zp -Tp
SET CFLAGSMT=-c -DSTRICT -G3 -MT -Ow -W3 -Zp -Tp
SET LINKER=link
SET GUIFLAGS=-SUBSYSTEM:windows
SET DLLFLAGS=-SUBSYSTEM:windows -DLL
SET GUILIBS=-DEFAULTLIB:user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
SET RC=rc
SET RCVARS=-r -DWIN32
****************************************************
Avatar of nietod
nietod

You said you had "no luck", but could you be more specific.  What is the problem?
Is there a reason you are using make files?  Using the VC deveopment environment is much easier.
Avatar of midnightexpress

ASKER

Edited text of question
Edited text of question
Edited text of question
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.

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.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.  
I didn't really solve your problems with my answer, but you did accept it.  Does that mean you've got it working?