Click here to Skip to main content
15,066,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

i know this question is somewhat duplicated however i have tried the solutions i have seen so far to no avail so i am looking to your for help.

I have an Unmanaged DLL (i do not have the source for the DLL only the DLL, LIB and Header file (C++). I have attempted to write a C++/CLR wrapper but i have no skills in C++ and really struggling.

The class has several entry points (but looking at the header file these functions are inside a class) but i am not sure how the CPP file is performing the function.

The documentation from the provider doesnt not show any thing regarding the construction of the class / functions or if anything needs doing before calling the functions directly.

This is the DllImport that i am trying to use to call teh InsertExclusion entry point but i keep getting the error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

<DllImport("AGDGatewayInterface.dll", CallingConvention:=CallingConvention.Cdecl, EntryPoint:="?InsertExclusion@CAGDGatewayInterface@@QAE?AW4AGDClientError@@JPADJ00@Z")> _
Public Sub InsertExclusion(
                                    lExclusionType As Integer,
                                   <MarshalAs(UnmanagedType.LPStr)> ByRef szValue As String,
                                    lAppId As Integer,
                                   <MarshalAs(UnmanagedType.LPStr)> ByRef szStartDate As String,
                                   <MarshalAs(UnmanagedType.LPStr)> ByRef szEndate As String
End Sub

        Dim val1 As String, val2 As String, val3 As String, val4 As Long, val5 As Long
        val1 = "012345678910"
        val2 = "2016-06-08 00:00:00"
        val3 = "2016-06-08 23:59:59"
        val4 = 3
        val5 = 0

        Call InsertExclusion(val4, val1, val5, val2, val3)

My question is really is that i do not know where i am going wrong to try and call this function or how if i need to call the CAGDGatewayInterface Class and then call the function from within the class?

Please can someone help me create the wrapper or get the right DllImports right for this please?

Entry Points in Unmanged C++ DLL.

UNDName of Entry Points
 1    0 00001080 public: __thiscall CAGDGatewayCallBack::CAGDGatewayCallBack(class CAGDGatewayCallBack const &)
 2    1 00001050 public: __thiscall CAGDGatewayCallBack::CAGDGatewayCallBack(void)
 3    2 00001D10 public: __thiscall CAGDGatewayInterface::CAGDGatewayInterface(char *,class CAGDGatewayCallBack *,char *,int,char *,int)
 4    3 00001E20 public: __thiscall CAGDGatewayInterface::~CAGDGatewayInterface(void)
 5    4 000010A0 public: class CAGDGatewayCallBack & __thiscall CAGDGatewayCallBack::operator=(class CAGDGatewayCallBack const &)
 6    5 000010C0 public: class CAGDGatewayInterface & __thiscall CAGDGatewayInterface::operator=(class CAGDGatewayInterface const &)
 7    6 0002A370 const CAGDGatewayCallBack::`vftable'
 8    7 00002B30 public: enum AGDClientError __thiscall CAGDGatewayInterface::CallBackUpdate(enum AGDCallbackUpdateType,int,int,int,char *,char *)
 9    8 00001A50 public: virtual void __thiscall CAGDGatewayCallBack::CallBackUpdateAck(enum AGDCallbackUpdateType,int,int,int,char *,char *,long,struct AGDGatewayDateTime &)
10    9 00001930 public: virtual void __thiscall CAGDGatewayCallBack::CallCleared(long,long,long,long,struct AGDGatewayDateTime &)
11    A 00003850 public: enum AGDClientError __thiscall CAGDGatewayInterface::DeleteAllExclusions(void)
12    B 000039B0 public: enum AGDClientError __thiscall CAGDGatewayInterface::DeleteExclusion(long,char *,long)
13    C 000026D0 private: bool __thiscall CAGDGatewayInterface::DeleteRecordSet(void)
14    D 00001430 private: void __thiscall CAGDGatewayInterface::Disconnect(void)
15    E 00001B90 public: virtual void __thiscall CAGDGatewayCallBack::Disposition(long,long,long,long,struct UserDefinedData &,struct AGDGatewayDateTime &)
16    F 000031A0 public: enum AGDClientError __thiscall CAGDGatewayInterface::EndSession(void)
17   10 00001570 public: void __thiscall CAGDGatewayInterface::ExecuteCCDown(void)
18   11 000016B0 public: void __thiscall CAGDGatewayInterface::ExecuteCCTimeOut(void)
19   12 000017E0 public: void __thiscall CAGDGatewayInterface::ExecuteCCUp(void)
20   13 00001AC0 public: virtual void __thiscall CAGDGatewayCallBack::FoundAgent(long,long,long,char *,struct AGDGatewayDateTime &)
21   14 00001070 public: void * __thiscall CAGDGatewayCallBack::GetInterface(void)
22   15 00002100 public: enum AGDClientError __thiscall CAGDGatewayInterface::GetMediaList(long,long)
23   16 00003C80 public: enum AGDClientError __thiscall CAGDGatewayInterface::InsertExclusion(long,char *,long,char *,char *)
24   17 00003B40 public: enum AGDClientError __thiscall CAGDGatewayInterface::InsertExclusionWithoutNotify(long,char *,long,char *,char *)
25   18 00002FA0 public: enum AGDClientError __thiscall CAGDGatewayInterface::KillAllCallsInService(long)
26   19 00002E90 public: enum AGDClientError __thiscall CAGDGatewayInterface::KillCall(long,long,long)
27   1A 00002200 public: enum AGDClientError __thiscall CAGDGatewayInterface::KillMediaCall(long)
28   1B 00003330 private: bool __thiscall CAGDGatewayInterface::LoginToCC(char *,int)
29   1C 00001CB0 public: virtual void __thiscall CAGDGatewayCallBack::MediaCallGone(bool,long)
30   1D 00001C50 public: virtual void __thiscall CAGDGatewayCallBack::MediaListCall(long,long,long,long,long,long,long)
31   1E 00002C60 public: enum AGDClientError __thiscall CAGDGatewayInterface::NewCall(long,struct UserDefinedData &,long)
32   1F 000019F0 public: virtual void __thiscall CAGDGatewayCallBack::NewCallAck(long,long,long,long,long,struct AGDGatewayDateTime &)
33   20 00002D70 public: enum AGDClientError __thiscall CAGDGatewayInterface::NewCallAgent(long,struct UserDefinedData &,long,char *)
34   21 00002020 public: enum AGDClientError __thiscall CAGDGatewayInterface::NotifyCCOfExclusionInsert(void)
35   22 00001260 private: void __thiscall CAGDGatewayInterface::PrintInBoundPacket(void *)
36   23 00001140 private: void __thiscall CAGDGatewayInterface::PrintOutGoingPacket(void *)
37   24 000022F0 private: void __thiscall CAGDGatewayInterface::ProcessPacket(void *)
38   25 00001B20 public: virtual void __thiscall CAGDGatewayCallBack::ReRoute(long,long,long,long,long,long,struct UserDefinedData &,struct AGDGatewayDateTime &)
39   26 00002010 private: enum AGDClientError __thiscall CAGDGatewayInterface::SendNewCallPacket(void *,long)
40   27 00001E50 private: enum AGDClientError __thiscall CAGDGatewayInterface::SendPacket(void *,long)
41   28 00003520 private: bool __thiscall CAGDGatewayInterface::SendTECommand(int,void *,int,int)
42   29 00001990 public: virtual void __thiscall CAGDGatewayCallBack::ServiceStatus(long,long,struct AGDGatewayDateTime &)
43   2A 00001060 public: void __thiscall CAGDGatewayCallBack::SetInterface(void *)
44   2B 000035F0 public: enum AGDClientError __thiscall CAGDGatewayInterface::StartSession(void)
45   2C 00003090 public: enum AGDClientError __thiscall CAGDGatewayInterface::UpdateCallData(long,long,long,struct UserDefinedData &)
46   2D 00001BF0 public: virtual void __thiscall CAGDGatewayCallBack::UpdateCallDataAck(long,long,long,long,struct AGDGatewayDateTime &)
47   2E 00001380 bool __cdecl WinSockInit(void)

Unmanaged C++ DLL Header
/*============================= File Header =================================+
 | $Archive: /CCProEngine/VERSION4_2_1/AGDGatewayInterface/AGDGatewayInterface.h $
 | $Revision: 16 $
 | $Date: 11/07/01 2:17p $
 | $Modtime: 11/07/01 2:17p $
 | $Author: Scontractor $

// Includes.
#include "AGDGatewaySharedTypes.h"

// Forward Declarations.
class CCProTEAsyncClient;

// Typedefs and Macros. (Where possible)
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the AGDGATEWAYINTERFACE_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// AGDGATEWAYINTERFACE_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#define AGDGATEWAYINTERFACE_API __declspec(dllexport)
#define AGDGATEWAYINTERFACE_API __declspec(dllimport)

// Externs and Globals.

// Enums and Constants.

// Function Declarations.
void TF_CenterCordAGDGatewayReceive(void *pData);

// Class Declarations.
	CAGDGatewayCallBack(void) {m_zInterface = NULL;}

	// Virtual Callback functions. Must be overridden in derived class.
	virtual void SessionStatus(long iStatus, long iServerId, AGDGatewayDateTime& zDateTime) = 0;
	virtual void LogErrorString(char* szErrStr, long iDebugLevel) = 0;

	// Virtual Callback functions. Need not be overridden in derived class if not needed.
	virtual void ServiceStatus(long iServiceId, long iServiceStatus, AGDGatewayDateTime& zDateTime);
	virtual void NewCallAck(long iRefId, long iStatus, long iSequenceNum, long iCallId, long iServiceId, AGDGatewayDateTime& zDateTime);
	virtual void FoundAgent(long iSequenceNum, long iCallId, long iServiceId, char* szAgentId, AGDGatewayDateTime& zDateTime);
	virtual void CallCleared(long iSequenceNum, long iCallId, long iServiceId, long iStatus, AGDGatewayDateTime& zDateTime);	
	virtual void Disposition(long iSequenceNum, long iCallId, long iServiceId, long iDisposition, UserDefinedData& zCallData, AGDGatewayDateTime& zDateTime);
	virtual void ReRoute(long iSequenceNum, long iNewCallId, long iOldCallId, long iNewServiceId, long iOldServiceId, long iStatus, UserDefinedData& zCallData, AGDGatewayDateTime& zDateTime);
	virtual void UpdateCallDataAck(long iSequenceNum, long iCallId, long iServiceId, long iStatus, AGDGatewayDateTime& zDateTime);
	virtual void MediaListCall(long iSequenceNum, long iCallId, long iServiceId, long iDuration, long iType, long iState, long iAgentId);
	virtual void MediaCallGone(bool bResult, long iCallId);

  // Callback management
  virtual void CallBackUpdateAck(AGDCallbackUpdateType eUpdateType, int iTableId, int iRecordNum, int iServiceId, char* szPhoneNum, char* szAgentId, long iStatus, AGDGatewayDateTime& zDateTime);

	void* m_zInterface;
	void  SetInterface(void* zInterface) { m_zInterface = zInterface; }
	void* GetInterface() { return m_zInterface; }

	CAGDGatewayInterface(char *szTenantShortName, CAGDGatewayCallBack* pzCallBack, char* pszPrimaryIpAddress = NULL, int iPrimaryPort = 0, char* pszBackupIpAddress = NULL, int iBackupPort = 0);

	// Commands Sent to the CenterCord.
	AGDClientError StartSession();
	AGDClientError NewCall(long iServiceId, UserDefinedData& zCallData, long iRefId);
	AGDClientError NewCallAgent(long iServiceId, UserDefinedData& zCallData, long iRefId, char *szAgent);
	AGDClientError KillCall(long iSequenceNum, long iCallId, long iServiceId);
	AGDClientError KillAllCallsInService(long iServiceId);
	AGDClientError UpdateCallData(long iSequenceNum, long iCallId, long iServiceId, UserDefinedData& zCallData);
	AGDClientError EndSession();
	AGDClientError DeleteExclusion(long lExclusionType, char* szValue, long lAppId);
	AGDClientError DeleteAllExclusions();
	// StartDate and EndDate should be in Universal format: yyyy-mm-dd hh:mm:ss
	AGDClientError InsertExclusion(long lExclusionType, char* szValue, long lAppId, char* szStartDate, char* szEndDate);
	AGDClientError InsertExclusionWithoutNotify(long lExclusionType, char* szValue, long lAppId, char* szStartDate, char* szEndDate);	
	AGDClientError NotifyCCOfExclusionInsert();
	AGDClientError GetMediaList( long iServiceId, long iDurationMin);
	AGDClientError KillMediaCall( long iCallId);
    // Callback management
    AGDClientError CallBackUpdate(AGDCallbackUpdateType eUpdateType, int iTableId, int iRecordNum, int iServiceId, char* szPhoneNum, char* szAgentId = NULL);

	CAGDGatewayCallBack*	m_pzCallBack;

	long  m_zSocket;
	long  m_iServerId;

	AGDClientError SendPacket(void* pzPacket, long iPacketSize);
	AGDClientError SendNewCallPacket(void* pzPacket, long iPacketSize);
	void ProcessPacket(void* pzInPacket);
	void PrintOutGoingPacket(void* pzOutPacket);
	void PrintInBoundPacket(void* pzOutPacket);
	bool LoginToCC(char* szCCIPAddress, int port);	
	void Disconnect();
	friend void TF_CenterCordAGDGatewayReceive(void *pData);
	void ExecuteCCDown();
	void ExecuteCCTimeOut();
	void ExecuteCCUp();

	CCProTEAsyncClient*				m_pzCCProTEAsyncClient;

	bool		SendTECommand(int iTransactionId, void* pData, int iSizeOfData, const int siTimeOutInMSecs=300);
	void*		m_pRecordSet;
	bool		DeleteRecordSet();


Included Files: AGDGatewaySharedTypes.h
#include "CCProCallData.h"

// Character string sizes.
const long	CCPRO_AGD_AGENT_ID_LENGTH			= 32;
const long  CCPRO_AGD_DATE_TIME_LENGTH  = 32;  
const long	CCPRO_AGD_FILENAME_LENGTH   = 80;
const long	CCPRO_AGD_ERROR_LENGTH      = 80;

// Service Status
enum AGDServiceStatus

// Debug levels
enum AGDLogDebugLevels
	iAGDDbgLevelNone			= 0,
	iAGDDbgLevelErrors		= 1,
	iAGDDbgLevelWarnings	= 2,
	iAGDDbgLevelTrace			= 3,
	iAGDDbgLevelAll				= 9,

// Errors returned directly by interface.
enum AGDClientError
	AGDErrorNone = 0,

// Status's returned from the Centercord.
enum AGDCCStatus
	AGDStatusOk = 0,                    // 0

	AGDStatusUnknown,                   // 1

	// SessionStatus
	AGDStatusConnected,                 // 2
	AGDStatusDisconnected,              // 3
	AGDStatusCCDown,                    // 4
	AGDStatusCCTimeOut,                 // 5
	AGDStatusCCUp,                      // 6

	// NewCallAck
	AGDStatusNewCall,                   // 7
	AGDStatusTooManyCalls,              // 8
	AGDStatusInvalidServiceId,          // 9

	// CallCleared
	AGDStatusAgentHungUp,               // 10
	AGDStatusAgentLoggedOut,            // 11
	AGDStatusCallKilled,                // 12
	AGDStatusInternalError,             // 13
	AGDStatusInactiveReRouteFailed,     // 14
	AGDStatusUnmannedReRouteFailed,     // 15
	AGDStatusQMaxTimeReRouteFailed,     // 16
	AGDStatusQMaxLenReRouteFailed,      // 17
	AGDStatusHolidayReRouteFailed,      // 18
	AGDStatusIVRCallEnded,	            // 19
	// ReRoute
	AGDStatusInactiveReRouted,          // 19
	AGDStatusUnmannedReRouted,          // 20
	AGDStatusQMaxTimeReRouted,          // 21
	AGDStatusQMaxLenReRouted,           // 23
	AGDStatusHolidayReRouted,           // 24

	// Xfer Status
	AGDStatusAgentTransferred,          // 25
	AGDStatusAgentTransferFailed,       // 26
	AGDStatusIVRTransferred,            // 27
	AGDStatusIVRTransferFailed,         // 28

	// UpdateCallDataAck
	AGDStatusUpdateCallDataSucceeded,   // 29
	AGDStatusUpdateCallDataFailed,      // 30

	// CallbackUpdate --- CQ 166316
	AGDStatusCallbackUpdateSucceeded,   // 31           // CQ 166316                               
	AGDStatusCallbackUpdateFailed,      // 32           // CQ 166316

enum AGDCallbackUpdateType    // CQ 166316

// Function Declarations.

// Class Declarations.

// Note that this is the SYSTEMTIME struct.
struct AGDGatewayDateTime
    unsigned short wYear;
    unsigned short wMonth;
    unsigned short wDayOfWeek;
    unsigned short wDay;
    unsigned short wHour;
    unsigned short wMinute;
    unsigned short wSecond;
    unsigned short wMilliseconds;


Included Files: ccprocalldata.h

/* FIX */
// do not like this redefinition here

enum AgentAssistType
	NLPAssistance         = 0,
	AgentAssistance       = 1,
	NLPAndAgentAssistance = 2
const int EMAIL_MAILBOX_SIZE =	256;

const int PHONE_NUMBER_STRING_SIZE				= 25;
const int FIRST_NAME_STRING_SIZE				  = 51;
const int LAST_NAME_STRING_SIZE				    = 21;
const int CALLBACK_MEMO_STRING_SIZE			  = 256;
const int USER_DEFINED_DATA_SIZE		      = 78;
const int ANI_STRING_SIZE									= 32;
const int DNIS_STRING_SIZE		            = 32;
const int CALLER_ID_STRING_SIZE		        = 48;
const int DISP_CODE_STRING_SIZE		        = 25;
const int MAX_USER_DEFINED_FIELDS           = 20;
const int TABLE_NAME_STRING_SIZE				  = 64;

// Screen Pop Data
typedef struct ScreenPopData
	//AODPhoneNumbers	phoneNums;

	char		szPhoneNumber[PHONE_NUMBER_STRING_SIZE];
	char		szFirstName[FIRST_NAME_STRING_SIZE];
	char		szLastName[LAST_NAME_STRING_SIZE];
	char		szDnis[DNIS_STRING_SIZE];
//	char		szDnis[MAX_SIP_ADDRESS_SIZE+1];

} ScreenPopData;

// User Defined Data
typedef struct
	// User Controlled Call Data (Application data)
	char		szUserDefined1[USER_DEFINED_DATA_SIZE];
	char		szUserDefined2[USER_DEFINED_DATA_SIZE];
	char		szUserDefined3[USER_DEFINED_DATA_SIZE];
	char		szUserDefined4[USER_DEFINED_DATA_SIZE];
	char		szUserDefined5[USER_DEFINED_DATA_SIZE];
	char		szUserDefined6[USER_DEFINED_DATA_SIZE];
	char		szUserDefined7[USER_DEFINED_DATA_SIZE];
	char		szUserDefined8[USER_DEFINED_DATA_SIZE];
	char		szUserDefined9[USER_DEFINED_DATA_SIZE];
	char		szUserDefined10[USER_DEFINED_DATA_SIZE];
	char		szUserDefined11[USER_DEFINED_DATA_SIZE];
	char		szUserDefined12[USER_DEFINED_DATA_SIZE];
	char		szUserDefined13[USER_DEFINED_DATA_SIZE];
	char		szUserDefined14[USER_DEFINED_DATA_SIZE];
	char		szUserDefined15[USER_DEFINED_DATA_SIZE];
	char		szUserDefined16[USER_DEFINED_DATA_SIZE];
	char		szUserDefined17[USER_DEFINED_DATA_SIZE];
	char		szUserDefined18[USER_DEFINED_DATA_SIZE];
	char		szUserDefined19[USER_DEFINED_DATA_SIZE];
	char		szUserDefined20[USER_DEFINED_DATA_SIZE];
} UserDefinedData;

typedef struct DCallData
	int				iEventCode;
	int			siCallID;
	int				siServiceID;
	int				siOriginalServiceID;

	// identifies call type and category
	int				iCallCategory;			
	int				iCallType;

	// Callback info
	int			siDialModeCode;
	int			siCallBackFlag;
	char			szCallbackMemo[CALLBACK_MEMO_STRING_SIZE];

	// CCPro Controlled Data( Screen POP Data)
	ScreenPopData	screenData;

	// User Defined Data
	UserDefinedData	userData;

	int			siMailQueId;
	int				iMessageId;
	char			szForwardToMBox[EMAIL_MAILBOX_SIZE];

	char			szTableName[TABLE_NAME_STRING_SIZE];
	int				iCallTableRecordNum;
	int				iStoreManagerId;
	int				iTargetManagerId;

} DCallData ;


What I have tried:

Writing a C++/CLR wrapper
Changing the DllImport CallingConvention
Several variations on pushing the strings through such as marshal.
Updated 9-Jun-16 0:40am

1 solution

Your are working in the wrong direction. The declaration is straitforward and not with "decorared names" and even so the data type declaration.

My tip is to write a C++ wrapper dll which calls the other dll. So you can separate the problems from marshalling and calling the dll.

But somebody else got already an answer to this question.
Dev O'Connor 9-Jun-16 6:43am
I have tried without the decorated names but only works with decorated calls but then i get the AccessViolation.

I have tried writing a wrapper for this DLL several times but C++ i do not know, i dont know the syntax, structure or how it is laid out. i dont know how to reference the class object or instantiate them (never used C++ before)

THis is why i tried with the marshalling but that doesnt work. do you know any services that i could supply this information to that could write it for me (even if its paid for) becuase ive spent over a week on this already and getting nowhere fast.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900