dll sample or walkthrough?

R

Randy

Hi, I need to create a simple dll which will be used by
MS Access and .ASP apps. What type of dll would be best
and can anybody point me to a complete example which I
can compile and run with Visual C++ .net?

Thanks,
Randy
 
G

Gary Chang

Hi Randy,

Thanks for you posting in the group!
Hi, I need to create a simple dll which will be used by
MS Access and .ASP apps...
What do you want the DLL to do with the MS Access and .ASP?
a complete example which I
can compile and run with Visual C++ .net?
VC++ Appwizard to create a Managed MFC Regular DLL
http://www.codeproject.com/managedcpp/managedmfcdll.asp?target=create|DLL


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy

Gary, functions in my dll will perform calculations and
access data then return values which will be used in
MSAccess and .ASP apps. I have a large amount of
existing C code which I'll use in the dll.
 
G

Gary Chang

Hi Randy,

Thanks for your quickly reply!
Gary, functions in my DLL will perform calculations and
access data then return values which will be used in
MSAccess and .ASP apps.

If you want your DLL can be used by ASP pages, I think you should create an
ATL COM DLL, it also can be loaded by Access applications.
For detail information on this topic, please refer to the following docs:

Developing Active Server Components with ATL
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasp/html/
comp.asp


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy

Gary, I found the following info in the vc++ help
documentation but I can't find the ATL COM AppWizard
anywhere. I have 'file|new|project|visual c++
projects|ATL|ATL project' so am I missing something?


Creating the Module
Creating the module is almost trivial: we select New.
from the File menu, and then select the Projects tab and
fill in the directory and project name. (Make sure you
don't pick the name of the control now-Dr. GUI usually
puts "Mod" at the end of the name to make sure.) Your
project dialog box will look something like the
following. (By the way, Dr. GUI thinks it's no accident
that "ATL COM AppWizard" is the default-or could it just
be first alphabetically?)

....

Creating the Object
Now that we understand the module object a little, let's
add a COM component to it.

The easiest way to add a COM component is to use the ATL
Object Wizard. Just select New ATL Object. from the
Insert menu, and you'll get a dialog box that looks like
the following.
 
G

Gary Chang

Hi Randy,

Thanks for your quickly reply!
and tried to plug in the code for the ToUpper simple
example but can't get it to compile.

After you created an ATL project with the DLL server type, in the ClassView
you can use the Add Class Wizard to add an ATL simple object, give a name,
use the default setting and click finish.
The in the ClassView right click the interface of the added ATL simple
object(e.g.: ICalssName), use Add method wizard to add the sample ToUpper
method.

Can you find an
example for vc++ .net?

The following link has many latest Visual C++ ATL samples:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/ht
ml/vcoricategoricallistofatlsamples.asp

Those samples may be not particularly for your ASP pages use, however to
assure the ATL object has Dual interface(ATL object Option), it can be
loaded by ASP pages.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Gary Chang

Hi Randy,
I can't find the ATL COM AppWizard
anywhere.

In VS.NET 2003, the ATL COM AppWizard is just the ATL Project Wizard .


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy

Thanks Gary, I got my dll to build and now I'm trying to
call the dll's function from a c++ app. How do I tell
the app where to find "C:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\test4.dll"? I looked at 'Imports' and 'using' and
project|properties but haven't found the answer yet.
 
G

Gary Chang

Hi Randy,

Thanks for your quickly response!
Thanks Gary, I got my dll to build and now I'm trying to
call the dll's function from a c++ app.

I think you DLL is an ATL COM server and automatically registered just
after building.
So you can use it in your C++ application as a COM object(for it actually
is).

If you use a managed C++ application, please refer to
HOW TO: Use ActiveX Components with Managed C++ Projects
http://support.microsoft.com/?id=816151#4



Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy

How do I tell my c++ app where to look for test4.dll and
it's functions? How will test4.dll's other users declare
test4.dll so they can use it's functions in c++,
msaccess, and .ASP apps on their systems?
 
G

Gary Chang

Hi Randy,

Thanks for your quickly response!
How do I tell my c++ app where to look for test4.dll and
it's functions? How will test4.dll's other users declare
test4.dll so they can use it's functions in c++,

If your test4.dll is a pure DLL(not a COM server), you can copy your DLL's
header file and .lib to your c++ program's directory, and include this
header file to your c++ program's header file or source file, then in the
Project\Setting...\Link tab's Catagory selecting Input, then in the
Object/Library Modules' textbox, type the .lib filename.

And meantime you should copy you .DLL file to the directory of the c++
application's exe file.


For .ASP page, it can only comsume the COM object, if you don't know clear
about how to use a COM within ASP, please post the problem to the
.dotnet.aspnet queue.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy

Gary, my property pages show that my project is a .dll
which is statically linked to ATL. How do I declare the
dll in c++, vba, and .ASP app? In vba i tried

Declare Sub rsdm1 Lib "Test4" ()

but get an error even if i copy test4.dll into the folder
which contains the .mdb file.
 
R

Randy Dietz

Gary, In some vba code I use

Private Declare Sub rsdm2 Lib "C:\Documents and
Settings\default\My Documents\Msaccess\Test4" (s1 As
String)
....
Dim s1 As String
rsdm2 (s1)

but it fails with the err

Can't find DLL entry point rsdm2 in C:\Documents and
Settings\default\My Documents\Msaccess\Test4

so what should I check?
 
G

Gary Chang

Hi Randy,

Hope you can review this message:
Gary, my property pages show that my project is a .dll which is statically
linked to ATL. How do I declare the dll in >c++, vba, and .ASP app? In
vba i tried
Declare Sub rsdm1 Lib "Test4" ()
but get an error even if i copy test4.dll into the folder which contains
the mdb file.

Which error do you get?
Is your Sub declaration compatible with your DLL's function signature?
And try to specify the fullname(include path name) of the Test4.dll instead
of just "Test4".

Please apply my suggestion above and let me know if it helps resolve your
problem.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy Dietz

in rsd2.cpp I have

STDMETHODIMP Crsd2::rsdm2(BSTR* s1)

then in msaccess (vba) code I use

Private Declare Sub rsdm2 Lib "C:\Documents and
Settings\default\My Documents\Msaccess\Test4" (ByVal s1
As String)
....
Dim s1 As String
rsdm2 (s1)

but it fails with the err

Can't find DLL entry point rsdm2 in C:\Documents and
Settings\default\My Documents\Msaccess\Test4

Is there some utility I can use to dump the dll's symbol
names and other info to show you? Maybe the dll type
isn't right for msaccess?
 
R

Randy Dietz

Gary, I tried to run dumpbin.exe on my dll but it fails
maybe because my environment variables aren't set up
correctly.

Here's my build log...

<html>
<head>
<META HTTP-EQUIV="Content-Type" content="text/html;
charset=Windows-1252">
</head>
<body>
<pre>
<table width=100% bgcolor=#CFCFE5><tr> <td> <font
face=arial size=+3>
Build Log
</font></table><table width=* cellspacing=0
cellpadding=0><tr><td width=0
bgcolor=#EDEDF5>&nbsp;</td><td width=0
bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>
<h3>------- Build started: Project: test4, Configuration:
Debug|Win32 -------
</h3>
</pre></table><table width=100%
bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Command Lines
</font></table><table width=* cellspacing=0
cellpadding=0><tr><td width=0
bgcolor=#EDEDF5>&nbsp;</td><td width=0
bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Creating
temporary file "c:\Documents and Settings\default\My
Documents\Visual Studio Projects\test4
\Debug\RSP000005.rsp" with contents
[
/Od /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_USRDLL" /D "
_ATL_ATTRIBUTES" /D "_WINDLL" /D "_ATL_STATIC_REGISTRY" /D
"_MBCS" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp"Debug/test
4.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /T
P
".\toupper.cpp"
".\test4.cpp"
".\rsd2.cpp"
".\rsd1.cpp"
]
Creating command line "cl.exe @"c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\RSP000005.rsp" /nologo"
Creating temporary file "c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\RSP000006.rsp" with contents
[
/Od /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_USRDLL" /D "
_ATL_ATTRIBUTES" /D "_WINDLL" /D "_ATL_STATIC_REGISTRY" /D
"_MBCS" /Gm /EHsc /RTC1 /MDd /Yc"stdafx.h" /Fp"Debug/test
4.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /T
P
".\stdafx.cpp"
]
Creating command line "cl.exe @"c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\RSP000006.rsp" /nologo"
Creating command line "rc.exe /d "_DEBUG" /l
0x409 /I "Debug" /fo"Debug/test4.res" ".\test4.rc""
Creating temporary file "c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\RSP000007.rsp" with contents
[
/OUT:"Debug/test4.dll" /INCREMENTAL /NOLOGO /DLL /IDLOUT:"
_test4.idl" /DEBUG /PDB:"Debug/test4.pdb" /SUBSYSTEM:WINDO
WS /IMPLIB:"Debug/test4.lib" /MACHINE:X86 /SYMBOLS
kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
".\Debug\rsd1.obj"
".\Debug\rsd2.obj"
".\Debug\stdafx.obj"
".\Debug\test4.obj"
".\Debug\toupper.obj"
".\Debug\test4.res"
]
Creating command line "link.exe @"c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\RSP000007.rsp""
Creating temporary file "c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\BAT000008.bat" with contents
[
@echo off
regsvr32 /s /c "c:\Documents and Settings\default\My
Documents\Visual Studio Projects\test4\Debug\test4.dll"
if errorlevel 1 goto VCReportError
goto VCEnd
:VCReportError
echo Project : error PRJ0019: A tool returned an error
code from "Performing registration"
exit 1
:VCEnd
]
Creating command line ""c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\BAT000008.bat""
</pre></table><table width=100%
bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Output Window
</font></table><table width=* cellspacing=0
cellpadding=0><tr><td width=0
bgcolor=#EDEDF5>&nbsp;</td><td width=0
bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Compiling...
stdafx.cpp
Compiling...
toupper.cpp
test4.cpp
rsd2.cpp
rsd1.cpp
Generating Code...
Compiling resources...
Linking...
LINK : warning LNK4044: unrecognized option '/SYMBOLS';
ignored
Creating library Debug/test4.lib and object
Debug/test4.exp
Microsoft (R) 32b/64b MIDL Compiler Version 6.00.0361
Copyright (c) Microsoft Corporation 1991-2002. All rights
reserved.
Processing .\_test4.idl
_test4.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\prsht.idl
prsht.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\wtypes.idl
wtypes.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\basetsd.h
basetsd.h
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\guiddef.h
guiddef.h
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\mshtml.idl
mshtml.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\ocidl.idl
ocidl.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\oleidl.idl
oleidl.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\objidl.idl
objidl.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\unknwn.idl
unknwn.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\oaidl.idl
oaidl.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\servprov.idl
servprov.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\urlmon.idl
urlmon.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\msxml.idl
msxml.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\dimm.idl
dimm.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\mshtmhst.idl
mshtmhst.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\docobj.idl
docobj.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\exdisp.idl
exdisp.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\objsafe.idl
objsafe.idl
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\oaidl.acf
oaidl.acf
Processing C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\include\ocidl.acf
ocidl.acf
Performing registration
</pre></table><table width=100%
bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
Results
</font></table><table width=* cellspacing=0
cellpadding=0><tr><td width=0
bgcolor=#EDEDF5>&nbsp;</td><td width=0
bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>
Build log was saved at "file://c:\Documents and
Settings\default\My Documents\Visual Studio Projects\test4
\Debug\BuildLog.htm"
test4 - 0 error(s), 1 warning(s)</pre></table><table
width=100% height=20 bgcolor=#CFCFE5><tr><td><font
face=arial size=+2>
</font></table></body></html>
 
R

Randy Dietz

Gary, I used

cd "C:\Documents and Settings\default\My
Documents\Msaccess"
call "C:\Program Files\Microsoft Visual Studio .NET 2003
\Common7\Tools\vsvars32.bat"
DUMPBIN.exe /ALL test4.dll > t.txt

and the 1st part of t.txt is

Microsoft (R) COFF/PE Dumper Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file test4.dll

PE signature found

File Type: DLL

FILE HEADER VALUES
14C machine (x86)
7 number of sections
4002F783 time date stamp Mon Jan 12 12:37:39 2004
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
210E characteristics
Executable
Line numbers stripped
Symbols stripped
32 bit word machine
DLL

OPTIONAL HEADER VALUES
10B magic # (PE32)
7.10 linker version
24000 size of code
11000 size of initialized data
0 size of uninitialized data
11884 entry point (10011884)
1000 base of code
1000 base of data
10000000 image base (10000000 to 10045FFF)
1000 section alignment
1000 file alignment
4.00 operating system version
0.00 image version
4.00 subsystem version
0 Win32 version
46000 size of image
1000 size of headers
0 checksum
2 subsystem (Windows GUI)
0 DLL characteristics
100000 size of stack reserve
1000 size of stack commit
100000 size of heap reserve
1000 size of heap commit
0 loader flags
10 number of directories
3D4A0 [ 1D8] RVA [size] of Export Directory
40000 [ B4] RVA [size] of Import Directory
42000 [ 14E0] RVA [size] of Resource
Directory
0 [ 0] RVA [size] of Exception
Directory
0 [ 0] RVA [size] of Certificates
Directory
44000 [ 12D4] RVA [size] of Base Relocation
Directory
35000 [ 1C] RVA [size] of Debug Directory
0 [ 0] RVA [size] of Architecture
Directory
0 [ 0] RVA [size] of Global Pointer
Directory
0 [ 0] RVA [size] of Thread Storage
Directory
0 [ 0] RVA [size] of Load
Configuration Directory
0 [ 0] RVA [size] of Bound Import
Directory
404D0 [ 41C] RVA [size] of Import Address
Table Directory
0 [ 0] RVA [size] of Delay Import
Directory
0 [ 0] RVA [size] of COM Descriptor
Directory
0 [ 0] RVA [size] of Reserved
Directory


SECTION HEADER #1
..textbss name
10000 virtual size
1000 virtual address (10001000 to 10010FFF)
0 size of raw data
0 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
E00000A0 flags
Code
Uninitialized Data
Execute Read Write

SECTION HEADER #2
.text name
23489 virtual size
11000 virtual address (10011000 to 10034488)
24000 size of raw data
1000 file pointer to raw data (00001000 to 00024FFF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60000020 flags
Code
Execute Read

RAW DATA #2
10011000: CC CC CC CC CC E9 56 1F 00 00 E9 7D D9 01 00
E9 ÌÌÌÌÌéV...é}Ù..é
10011010: EC AF 01 00 E9 37 7A 01 00 E9 A2 41 01 00 E9
FD ì¯..é7z..é¢A..éý
10011020: FC 00 00 E9 C8 A5 00 00 E9 D3 6C 01 00 E9 2E
67 ü..éÈ¥..éÓl..é.g
 
G

Gary Chang

Hi Randy,

Thanks for your quickly reply!
Can't find DLL entry point rsdm2 in C:\Documents and
Settings\default\My Documents\Msaccess\Test4

The code you posted is using an exported function rsdm2 in the Test4.dll,
however the Test4.dll is a COM in-process server which built by ATL wizard,
not a pure DLL with function exported, so you got this error.

If you want to load an exported function of a dll, you can create the dll
as a Win32 Dynamic-Link Library.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Gary Chang

Hi Randy

Thanks for your quickly reply!
Private Declare Sub rsdm2 Lib "C:\Documents and
Settings\default\My Documents\Msaccess\Test4" (ByVal s1
As String)

It is a declaration of rsdm2 function which assumed exported from the
Test4.dll(assume not a COM server).

STDMETHODIMP Crsd2::rsdm2(BSTR* s1)

This is a member method definition of your COM class Crsd2, and not an
exported function.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
R

Randy Dietz

Hi, my original question was how to create a simple dll
which will be used by
MS Access and .ASP apps and what type of dll would be
best
and could anybody point me to a complete example which I
could compile and run with Visual C++ .net.

You suggested that I should create an
ATL COM DLL which could also be loaded by MS Access
applications so I tried

file|new|project|visual c++ projects|ATL|ATL project

but it fails with the err

Can't find DLL entry point rsdm2 in C:\Documents and
Settings\default\My Documents\Msaccess\Test4

so now you tell me to use an exported function of a Win32
Dynamic-Link Library. I used

file|new|project|visual c++ projects|win32|win32 project

then I set the configuration type to dll. I can't find a
wizard which will add a method so can you please give me
example code for a method that I can paste into my win32
dll source files and call it from MAccess and .ASP apps?

Thanks
Randy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top