Click here to Skip to main content
15,846,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All;

I am working on C++/MFC project where I need to consume an active x control, so I create a control like
CZKEM1 m_zktecoCtrl;
but when I try to invoke it Like
bool bConnect = false;
	bConnect = m_zktecoCtrl.Connect_Net(L"192.168.1.201", 4370);
a message popup say
"Invalid number of parameters"


What I have tried:

code in my Control h file

C++
#pragma once

// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated
// by Microsoft Visual C++, your modifications will be overwritten.

/////////////////////////////////////////////////////////////////////////////

#include "afxwin.h"

class CZKEM1 : public CWnd
{
protected:
	DECLARE_DYNCREATE(CZKEM1)
public:
	CLSID const& GetClsid()
	{
		static CLSID const clsid
			= { 0x00853a19,0xbd51,0x419b,{0x92,0x69,0x2d,0xab,0xe5,0x7e,0xb6,0x1f} };
		return clsid;
	}
	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
		const RECT& rect, CWnd* pParentWnd, UINT nID,
		CCreateContext* pContext = nullptr)
	{
		return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
	}

	BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
		UINT nID, CFile* pPersist = nullptr, BOOL bStorage = FALSE,
		BSTR bstrLicKey = nullptr)
	{
		return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
			pPersist, bStorage, bstrLicKey);
	}

	// Attributes
public:


	// Operations
public:
	// _IZKEMEvents

	// Functions
	//

	BOOL Connect_Net(BSTR IPAdd, long Portl)
	{
		BOOL result;
		static BYTE parms[] = VTS_BSTR VTS_I4;
		InvokeHelper(0x15, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, IPAdd, Portl);
		return result;
	}

	};


My code in Dialog h file

C++
public:

	CZKEM1 m_zktecoCtrl;


}

My code in Dialog cpp file

C++
void CzkTestDlg::OnBnClickedConnectButton()
{
	bool bConnect = false;
	bConnect = m_zktecoCtrl.Connect_Net(L"192.168.1.201", 4370);
	if (bConnect)
	{
		MessageBox("Connection Succeeded ");
	}
	else MessageBox("Connection Failed");
}
Posted
Updated 16-Mar-23 3:01am
v4
Comments
Richard MacCutchan 16-Mar-23 4:55am    
The Read method obviously expects some parameters. Check the documentation to see what is required.
Zouaoui Billel 16-Mar-23 7:44am    
I update the question,thank you...

Someone here would (correctly) write: "This is not a good question [...]".
As Richard pointed out, at least one argument is expected.
You should post here, at least, the Read method prototype in order to get meaningful help.
[update]
Your Connect_Net call looks correct (I mean, it has the right number of parameters). Are you sure the error message is related to such a call?
[/update]
 
Share this answer
 
v3
Comments
Zouaoui Billel 16-Mar-23 7:41am    
I updated the question , now may looks like a good question...
thank you.
CPallini 16-Mar-23 7:58am    
Fine. However, I am sure, you could do better. See my updated answer.
As far as I can see your code should not compile, because of:
C++
static BYTE parms[] = VTS_BSTR VTS_I4;

The elements of an array should be separated by commas, thus:
C++
static BYTE parms[] = { VTS_BSTR, VTS_I4 };
                                ^
 
Share this answer
 
v2

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