Solved

ATL COM dll which exports symbols

Posted on 2003-11-10
7
500 Views
Last Modified: 2013-12-14
You can create an ATL COM-dll, this dll has a typelibrary to access the internal functions.

You can also create a DLL which exports some symbols.

But now, I want to create an ATL-COM DLL which exports some functions and structs:

//code//
; DPD_Dll.def : Declares the module parameters.

LIBRARY      "Dll.DLL"

EXPORTS
      DllCanUnloadNow     @1 PRIVATE
      DllGetClassObject   @2 PRIVATE
      DllRegisterServer   @3 PRIVATE
      DllUnregisterServer      @4 PRIVATE
\\code\\

That's from an ATL com DLL...

But now I want to export the struct 'route' and the function 'findroute' and the object (class) 'CMaptool'

How can I do this?
0
Comment
Question by:G00fy
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Expert Comment

by:_ys_
ID: 9716059
All be it possible, I highly recommend against it.

COM dynamically loads/unloads dlls as it uses them. As such your dll could be unloaded when a client has a handle on your exported struct or class - which would not be good.

If you really must, your struct can be defined purely in IDL, allowing it to be redistributed as part of the type library.
0
 

Author Comment

by:G00fy
ID: 9716095
No, I just want the Dll to be used OR by accessing it via IDL, or via default windows API's...

If they (the people who use it) want to mix them... I don't care... The IDL frontend has all the objects and functions and structs and such. So it's nearly done.

But now I want to include the API-frontend.


Another question came to my head:
when I access the dll via API, how is the load/unloading done? Is it loaded before every api-call, and unloaded after each api-call? Or stays it resident in memory? Or does it get a ReferenceCounter (like with COM-elements) that when it hits 0, it is unloaded?
0
 
LVL 9

Assisted Solution

by:_ys_
_ys_ earned 40 total points
ID: 9716177
>> No, I just want the Dll to be used OR by accessing it via IDL, or via default windows API's...

Just making you aware of the potential issues.

Prefixing your declaration with __declspec(dllexport), exports symbols from a dll.

__declspec(dllexport) void findRoute( );

You may wish to prefix that prefix with ectern "C" as well. This prevents the C++ compiler from mangling to function name.

extern "C" __declspec(dllexport) void findRoute( );

Without this extern "C" client calls to GetProcAddress("findRoute") would fail.
extern "C" alleviates this and allows it to succeed. (The function names could alternatively be added to the def file to alleviate this).

>> when I access the dll via API, how is the load/unloading done? Is it loaded before every api-call, and unloaded after each api-call? Or stays it resident in memory? Or does it get a ReferenceCounter (like with COM-elements) that when it hits 0, it is unloaded?

Unless 'dll delayed loading' is enabled when compiling a project those referenced dlls are loaded when the process itself loads. They remain resident until the process terminates - or until a call to UnloadLibrary is performed.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 49

Accepted Solution

by:
DanRollins earned 60 total points
ID: 9763089
Using 'normal' non-COM styel access to the DLL, one typically does *not* export data.  One typically provides access functions.  However, it is perfectly possible.  Just follow these steps:

1) Use the AppWizard to create a new app:  
   type: Win32 Dynamic Link Library
   name: MyTestDLL
then [OK]

2) Select "A DLL that exports some symbols"   Then click [Finish]

3) Open MyTestDLL.h and add this to the bottom:

//------------------------ define the data structure
typedef struct {
      int   nLen;
      char  szName[30];
      char  szAddr[30];
} MYSTRUCT;

//------------------------ export an instance of that data
extern MyTestDLL_API MYSTRUCT rExportedStruct;

4) Open MyTestDLL.cpp and add this to the bottom:

MyTestDLL_API MYSTRUCT rExportedStruct= {1,"Dan","anytown USA"};

5)  Build the project.

6)  Create another testing project... Win32 Console.  Make it so:

#include "\MyProj\zEETests2\MyTestDLL\MyTestDLL.h"
#pragma comment(lib, "\\MyProj\\zEETests2\\MyTestDLL\\Debug\\MyTestDLL.lib" )
#include <stdio.h>

void main()
{
      MYSTRUCT* pr= &rExportedStruct;

      printf( "name is %s \r\n", pr->szName );
}

7) Before running this, copy the DLL from the ..\MyTestDLL\Debug and put it into the same directory as the EXE.  
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
And that is all there is to it.

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9784108
G00fy,
Does that help you?
-- Dan
0
 

Author Comment

by:G00fy
ID: 9788966
I have not tried it yet... I will update this question as soon as I start with this... In the meantime ;) you might be able to answer the other question I'm going to ask in a minute on this very same site.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10248847
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: _ys_ {http:#9716177} & DanRollins {http:#9763089}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
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…

623 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