From: worlman385 on
for creating a DLL in VC++ 2005, what's the following do? is it a must
have?

#ifdef _USRDLL
#define EPGLIB_API __declspec( dllexport )
#else /* _USRDLL */
#define EPGLIB_API __declspec( dllimport )
#endif /* _USRDLL */
======================

for each function that' call by DLL user, I must add

PROJECTName_API + return type + PASCAL + functionName like follows?
why related to PSCAL??

EPGLIB_API BOOL PASCAL CreateEPGLibInstance();
EPGLIB_API HRESULT PASCAL LoadXMLData(LPCTSTR tszXMLFileName);
EPGLIB_API HRESULT PASCAL PostSoapRequest();

======================

// EPGLib.h : main header file for the EPGLib DLL
//

#pragma once

#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h" // main symbols


// CEPGLibApp
// See EPGLib.cpp for the implementation of this class
//

class CEPGLibApp : public CWinApp
{
public:
CEPGLibApp();
HRESULT LoadXMLData(LPCTSTR tszXMLFileName);

// Overrides
public:
virtual BOOL InitInstance();
virtual int ExitInstance();

DECLARE_MESSAGE_MAP()
};


#ifdef _USRDLL
#define EPGLIB_API __declspec( dllexport )
#else /* _USRDLL */
#define EPGLIB_API __declspec( dllimport )
#endif /* _USRDLL */

EPGLIB_API BOOL PASCAL CreateEPGLibInstance();
EPGLIB_API HRESULT PASCAL LoadXMLData(LPCTSTR tszXMLFileName);
EPGLIB_API HRESULT PASCAL PostSoapRequest();
From: worlman385 on
When I implement a DLL, should I always have the following 2 function?

are these 2 function will load the DLL into memory and unload from
memory??

what's CoInitialize(NULL)??

==============================

BOOL CEPGLibApp::InitInstance()
{
CWinApp::InitInstance();

if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}

CoInitialize(NULL);

return TRUE;
}

int CEPGLibApp::ExitInstance()
{
CoUninitialize();

return CWinApp::ExitInstance();
}

From: Dan Bloomquist on
worlman385(a)yahoo.com wrote:
> for creating a DLL in VC++ 2005, what's the following do? is it a must
> have?
>
> #ifdef _USRDLL
> #define EPGLIB_API __declspec( dllexport )
> #else /* _USRDLL */
> #define EPGLIB_API __declspec( dllimport )
> #endif /* _USRDLL */
> ======================

That is fine. I don't know if it is more official to use:
#ifdef HECRAFT_DLL_COMPILE
#define HECRAFT_EXPORT AFX_CLASS_EXPORT
#else
#define HECRAFT_EXPORT AFX_CLASS_IMPORT
#endif

> for each function that' call by DLL user, I must add
>
> PROJECTName_API + return type + PASCAL + functionName like follows?
> why related to PSCAL??
>
> EPGLIB_API BOOL PASCAL CreateEPGLibInstance();
> EPGLIB_API HRESULT PASCAL LoadXMLData(LPCTSTR tszXMLFileName);
> EPGLIB_API HRESULT PASCAL PostSoapRequest();

The PASCAL is unnecessary. My docs say it is obsolete.

>
> class CEPGLibApp : public CWinApp
> {
> public:
> CEPGLibApp();
> HRESULT LoadXMLData(LPCTSTR tszXMLFileName);
>
> // Overrides
> public:
> virtual BOOL InitInstance();
> virtual int ExitInstance();
>
> DECLARE_MESSAGE_MAP()
> };
>
> EPGLIB_API BOOL PASCAL CreateEPGLibInstance();
> EPGLIB_API HRESULT PASCAL LoadXMLData(LPCTSTR tszXMLFileName);
> EPGLIB_API HRESULT PASCAL PostSoapRequest();

See TN033 about exporting class members. This won't link as the members
look to be declared as globals.

You would
class A
{
AFX_EXT_CLASS void Member( );
};

If you don't want to export the whole class.

But there is more to it as you are creating a CWinApp. Are you sure that
is what you want to do?

Best, Dan.


From: Dan Bloomquist on
worlman385(a)yahoo.com wrote:
> When I implement a DLL, should I always have the following 2 function?
>
> are these 2 function will load the DLL into memory and unload from
> memory??
>
> what's CoInitialize(NULL)??

You could put that in the VS search or google. Short answer, no.

CEPGLibApp came up on a search in a thread started by 'June Lee' on the
21st, same members.

In June's code there is a COM object, so yes.

Me thinks you have a plate full if June is gone and now it is your job...

Best, Dan.
From: Joseph M. Newcomer on
See below
On Wed, 26 Mar 2008 17:12:13 -0800, worlman385(a)yahoo.com wrote:

>for creating a DLL in VC++ 2005, what's the following do? is it a must
>have?
>
>#ifdef _USRDLL
>#define EPGLIB_API __declspec( dllexport )
>#else /* _USRDLL */
>#define EPGLIB_API __declspec( dllimport )
>#endif /* _USRDLL */
>======================
>
>for each function that' call by DLL user, I must add
>
>PROJECTName_API + return type + PASCAL + functionName like follows?
>why related to PSCAL??
>
>EPGLIB_API BOOL PASCAL CreateEPGLibInstance();
>EPGLIB_API HRESULT PASCAL LoadXMLData(LPCTSTR tszXMLFileName);
>EPGLIB_API HRESULT PASCAL PostSoapRequest();
****
PASCAL should *never* be used; it died with Win16, and its appearance in Win32 is always
an error.

You can use WINAPI or CALLBACK or one of the other representatives of __stdcall if you
wish, but none of these are actually required.

But yes, you have the right idea here. I would not use the _USRDLL flag for this purpose,
I would use a name of my own referring to my header file and my project, because if a DLL
is calling another DLL, the _USRDLL will be defined for the caller as well as the called.
****
>
>======================
>
>// EPGLib.h : main header file for the EPGLib DLL
>//
>
>#pragma once
>
>#ifndef __AFXWIN_H__
> #error "include 'stdafx.h' before including this file for PCH"
>#endif
>
>#include "resource.h" // main symbols
>
>
>// CEPGLibApp
>// See EPGLib.cpp for the implementation of this class
>//
>
>class CEPGLibApp : public CWinApp
>{
>public:
> CEPGLibApp();
> HRESULT LoadXMLData(LPCTSTR tszXMLFileName);
>
>// Overrides
>public:
> virtual BOOL InitInstance();
> virtual int ExitInstance();
>
> DECLARE_MESSAGE_MAP()
>};
>
>
>#ifdef _USRDLL
>#define EPGLIB_API __declspec( dllexport )
>#else /* _USRDLL */
>#define EPGLIB_API __declspec( dllimport )
>#endif /* _USRDLL */
>
>EPGLIB_API BOOL PASCAL CreateEPGLibInstance();
>EPGLIB_API HRESULT PASCAL LoadXMLData(LPCTSTR tszXMLFileName);
>EPGLIB_API HRESULT PASCAL PostSoapRequest();
****
Delete every occurrence of PASCAL, either replacing it with something that was not made
obsolete in 1992 or not using it at all.

Change _USRDLL to a symbol you define in your DLL before doing the #include of your header
file.
joe
****
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm