Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem writing string #12

Open
Zeno82 opened this issue Sep 24, 2019 · 0 comments
Open

Problem writing string #12

Zeno82 opened this issue Sep 24, 2019 · 0 comments

Comments

@Zeno82
Copy link

Zeno82 commented Sep 24, 2019

Hi everybody,

I have read/write access to a string variable. It's a VT_BSTR.
Reading works fine, I have issues with writing.

First question is: how do I know how many charachters (or bytes) I'm allowed to write, if I didn't get any specs in advance?

Second: How do I make use of all the space I have available?
I ask this because when the string holds, e.g., 10 wchars, I can only write 10 or less.
Using Matrikon OPC I can write all the characters number the PLC developer told me.
My code so far:

std::wstring str(L"The string I want to write");
OPCItemData data;
var.pItem->readSync(data, OPC_DS_DEVICE);
wcscpy_s(data.vDataValue.bstrVal, 64, str.c_str()); // I know I have 64 wchars available
var.pItem->writeSync(data.vDataValue);

"var" is a struct I created:

struct VARIABILE  
{  
	std::string Nome;  
	COPCItem* pItem;  
	VARTYPE tipo;  
};

The above code works well only if the string already holds more than str.length(), otherwise the string gets truncated (and I fear I might be overwriting memory areas somewhere).

Any help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant