Solved

ATL COM dll which exports symbols

Posted on 2003-11-10
7
499 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
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…

710 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