Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ATL COM dll which exports symbols

Posted on 2003-11-10
7
Medium Priority
?
505 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
  • 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 160 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 49

Accepted Solution

by:
DanRollins earned 240 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

824 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