Click here to Skip to main content
15,905,683 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: conversion from char* to string Pin
Johann Gerell14-May-08 21:47
Johann Gerell14-May-08 21:47 
GeneralUsing WTL/ATL in a static library Pin
mateuscb3-Apr-08 3:42
mateuscb3-Apr-08 3:42 
GeneralRe: Using WTL/ATL in a static library Pin
mateuscb3-Apr-08 7:24
mateuscb3-Apr-08 7:24 
QuestionCan u hand over CStrings from MFC to a WTL DLL? [modified] Pin
DaveB229-Mar-08 1:51
DaveB229-Mar-08 1:51 
AnswerRe: Can u hand over CStrings from MFC to a WTL DLL? Pin
Stuart Dootson29-Mar-08 16:25
professionalStuart Dootson29-Mar-08 16:25 
GeneralRe: Can u hand over CStrings from MFC to a WTL DLL? Pin
DaveB229-Mar-08 23:41
DaveB229-Mar-08 23:41 
GeneralRe: Can u hand over CStrings from MFC to a WTL DLL? Pin
Stuart Dootson30-Mar-08 2:25
professionalStuart Dootson30-Mar-08 2:25 
GeneralRe: Can u hand over CStrings from MFC to a WTL DLL? Pin
DaveB231-Mar-08 0:10
DaveB231-Mar-08 0:10 
Excellent. This works perfectly - have tested it now, here's a summary of the working method for the benefit of other readers.

The typedef is in the interface .h, so all you need to do in the MFC is

#include "../wherever/QXMyWrapper.h"
#pragma comment(lib, "../whereverlibis/QXMyWrapper")

In the MFC, can now do all the usual CString operations and function calls, and can transfer other CStrings easily in and out of the QXString form like this

QXMyWrapper wrapper;
CString cstr("qwertyuiop");
QXString str = cstr;
int k = wrapper.Hello(str);
// str is modified by Hello


The working QXMyWrapper.h looks like this...
//--------------------------------------------------------------------------
/*
File name: QXMyWrapper.h

This file contains all the DLL interfacing object declarations,

Notice: we use the same header file for compiling the .DLL and the .exe (application).
The header file exports the target DLL objects if we are building the DLL,
otherwise it imports the DLL objects into an application which uses the DLL.
Here we assume the DLL is being built in WTL/ATL and the caller is an MFC app, so we use _AFX to differentiate the two

Based on http://www.codeproject.com/KB/DLL/RegDLL.aspx
and http://www.codeproject.com/script/Forums/View.aspx?fid=4486
*/
#ifndef _QXMYWRAPPER_H_
#define _QXMYWRAPPER_H_

#ifdef _AFX // MFC apps define this
#define DECLDIR __declspec(dllimport)
#include <atlstr.h> // allows us to use QXString in MFC
#else
#define DECLDIR __declspec(dllexport)
// WTL definitions for the non MFC environment
#include <atlstr.h>
#include <atlbase.h>
#include <atlapp.h>
#define _WTL_NO_CSTRING
#include <atlmisc.h>
#endif

// Define QXString as a specialized CStringT which will behave like the usual MFC CString but
// is consistently defined and has consistent mem (re)allocation between MFC callers and the DLL
typedef CStringT<char, StrTraitATL<char> > QXString;

class DECLDIR QXMyWrapper
{
public:
  QXMyWrapper();
  ~QXMyWrapper();
  int Hello(QXString& name);
};

#endif // _QXMYWRAPPER_H_
//--------------------------------------------------------------------------

Finally, in the WTL .cpp you can put all the other stuff you need to implement the wrapper, and this is where all the other #include's needed for your WTL code go, so the shared .h doesn't drg them in and confuse the MFC code. This lets you wrap a WTL DLL effectively and keep it separate from the MFC. The other nice thing is that the debugging works fine, you can step in and out of the WTL code during an MFC debugging session and watch what is happening. Many thanks for the accurate comments to make this all work...

DaveB

QuestionATL service: Call to LoadLibrary Fails. Pin
abhijitr28-Mar-08 5:53
abhijitr28-Mar-08 5:53 
GeneralRe: ATL service: Call to LoadLibrary Fails. Pin
Stuart Dootson29-Mar-08 16:33
professionalStuart Dootson29-Mar-08 16:33 
Questionwhy WTL ListViewCtrl's LVN_GETDISPINFO notification is not getting fired? Pin
Ram-Murthi28-Mar-08 1:43
Ram-Murthi28-Mar-08 1:43 
AnswerRe: why WTL ListViewCtrl's LVN_GETDISPINFO notification is not getting fired? Pin
Ram-Murthi30-Mar-08 19:42
Ram-Murthi30-Mar-08 19:42 
AnswerRe: why WTL ListViewCtrl's LVN_GETDISPINFO notification is not getting fired? Pin
PuttyTree23-Nov-11 20:47
PuttyTree23-Nov-11 20:47 
GeneralUnable to open file for reading using C++ I/O [modified] Pin
ComplexLifeForm26-Mar-08 23:34
ComplexLifeForm26-Mar-08 23:34 
GeneralRe: Unable to open file for reading using C++ I/O Pin
led mike27-Mar-08 5:00
led mike27-Mar-08 5:00 
GeneralRe: Unable to open file for reading using C++ I/O Pin
CPallini27-Mar-08 5:29
mveCPallini27-Mar-08 5:29 
GeneralRe: Unable to open file for reading using C++ I/O [modified] Pin
ComplexLifeForm27-Mar-08 7:21
ComplexLifeForm27-Mar-08 7:21 
GeneralRe: Unable to open file for reading using C++ I/O Pin
CPallini27-Mar-08 9:56
mveCPallini27-Mar-08 9:56 
QuestionNeed Help on ATL Project Pin
manish.patel25-Mar-08 22:20
manish.patel25-Mar-08 22:20 
GeneralRe: Need Help on ATL Project Pin
Michael Dunn26-Mar-08 17:58
sitebuilderMichael Dunn26-Mar-08 17:58 
GeneralRe: Need Help on ATL Project Pin
manish.patel30-Mar-08 22:34
manish.patel30-Mar-08 22:34 
QuestionHow to use GDI+ in an ActiveX Control? [modified] Pin
samfromcn18-Mar-08 4:54
samfromcn18-Mar-08 4:54 
GeneralRe: How to use GDI+ in an ActiveX Control? Pin
samfromcn18-Mar-08 15:43
samfromcn18-Mar-08 15:43 
GeneralRe: How to use GDI+ in an ActiveX Control? Pin
Michael Dunn20-Mar-08 13:40
sitebuilderMichael Dunn20-Mar-08 13:40 
General'Server busy' problem Pin
KASR117-Mar-08 19:21
KASR117-Mar-08 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.