 |
|
 |
Hi all!
I want to know if it's possible to convert an object from HANDLE to BSTR. And if it is, I need the way to do that.
Thanks to all.
|
|
|
|
 |
|
 |
I got to use an activeX control in my Embedded vc++ 4.0 project. When I import the control its wrapper class had a function as below,
Bool CMyCtrl::AFunction(BSTR* bstValue)
{
BOOL result;
static BYTE parms[] =
VTS_PBSTR;
InvokeHelper(0x50, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms,
bstValue)
return result;
}
I tried to pass the parameters as below,
CString str = "No Data ";
BSTR FAR bstData = str.AllocSysString();
m_dvt.AFunction((BSTR*)bstData);
Type Mismatch Error Shows
How I should pass the parameter
The same code is doing well in VC++6.0
|
|
|
|
 |
|
 |
I got to use an activeX control in my VC++ project. When I import the control its wrapper class had a function as below,
void CVTSID::Connect(BSTR* RemHost, long* RemPort)
{
static BYTE parms[] = VTS_PBSTR VTS_PI4;
InvokeHelper(0x60030012, DISPATCH_METHOD, VT_EMPTY, NULL, parms, RemHost, RemPort);
}
I tried to pass the parameters as below,
CString str = "192.168.1.155";
BSTR host = str.AllocSysString();
long port = 3246;
m_dvt.Connect(&host,&port);
The function fails!
How I should pass the parameter
|
|
|
|
 |
|
 |
Is there a protocol issue when Serializing data using Serialize method of MFC C++ over a TCP Socket to a Java App. If not how can this be done?
The model is: A java client connect a server written in C++ and Serialization of a Class or an Object containg data takes place. If you can help me I'll be very happy.
Cheers
Sean V
|
|
|
|
 |
|
 |
This can not be done as the binary formats of object are quite different between C++ and Java. Either a proprietary binary format or a higher level exchange format needs to be used (e.g. SOAP, CORBA).
|
|
|
|
 |
|
 |
Hi,
I need to set/get string properties with embedded null chars within in an ActiveX.
My VB call will be :
myCtl.Read = "this" & chr$(0) & "is" & chr$(0) & "a" & chr$(0) & "test" & chr$(0)
sValue$ = myCtl.Read 'I must retrieve the entire string not the first part terminated with a null char.
My C++ :
DISP_PROPERTY_EX(CMyCtl, "Read", GetRead, SetRead, ???) // <- what
to place to handle a BSTR*
BSTR CMyCtl::GetRead()
{
????? // <- what to place to handle a BSTR*
}
void CMyCtl::SetRead(????? lpszNewValue)
{
????? // <- what to place to handle a BSTR*
SetModifiedFlag();
}
Regards,
Michael
|
|
|
|
 |
|
 |
I am trying to find all the info can about CArchive to
store a only one object and I would like to know if CArchive will compress or encrypt
the data in the achive(with any help from me) because it needs the archive to be small and
secure for internet transfer and the object in the archive will contain passwords for access.
Now I do know that once transfer onto the users computer there is still chane a could be a
hacker program to somehow get the decryted password from memory.
Geting Back to CAchive....
What the archive is going to used for is one of my program, that won't be free(oh, I am sorry some of
my programs have to stay undisclosed)and is the starting builder of the archive and the achive is released
to the user of my other program, that will be free(undisclosed for now but I do have a feeling someday
I will post on this site docs/classes to use it the free program.) will be able to access the achive get password
for the rest of the archive and may have the archive regenerate with information changing with each uses.
This is just letting you know where I am/maybe going with these programs so I can learn more about CArchive.
Also will hope to support the following:
Win32API, MFC 6.0, COM, ALT, Win95/98/2000Me, NT4.0WorkStation/Server, Win2000Pro/Server, .NET
don't worry if you cant you can still repy(like I support Win32API but CAchive doesn't also Win2000ME and .NET is out yet).
Thanks...
|
|
|
|
 |
|
 |
My starting reply had a view errors here is an replacement...
I am trying to find all the info can about CArchive to
store a only one object and I would like to know if CArchive will compress or encrypt
the data in the achive(without any help from me) because the archive need to be small and
secure for internet transfer and the object in the archive will contain passwords for
access.
Now I do know that once transfer onto the users computer there is still chane a could be a
hacker program to somehow get the decryted password from memory.
Getting Back to CAchive....
What the archive is going to used for is one of my program, that won't be free(oh, I am
sorry some of
my programs have to stay undisclosed)and is the starting builder of the archive and the
achive is released
to the user of my other program, that will be free(undisclosed for now but I do have a
feeling someday
I will post on this site docs/classes to use the free program.) will be able to access
the achive get password
for the rest of the archive and may have the archive regenerate with information changing
with each uses.
This is just letting you know where I am/maybe going with these programs so I can learn
more about CArchive.
Also will hope to support the following:
Win32API, MFC 6.0, COM, ALT, Win95/98/2000Me, NT4.0WorkStation/Server, Win2000Pro/Server,
.NET
don't worry if you cant you can still repy(like I support Win32API but CAchive doesn't also
Win2000ME and .NET is out yet).
Thanks...
|
|
|
|
 |
|
 |
Well, the only *real* problem with this code was that it leaked memory. The problem is in the mf.Detach() which leaves the original pointer to the memory out in Timbuktu. When mf is destroyed it fails to clean up the memory it used. Once that was fixed that it ran fine. The SysAllocByteString() function appears to be working just fine to package up the serialized stuff. This isn't intended to be a general approach. It's a simple hack between 2 VC++ programs on Wintel machines. Little end/Big end aren't issues here. It's MFC after all.
I use this template in the real code.
BSTR x_bstr_p::x_to_bstr(T* const object)
{
BSTR A;
CMemFile mf;
CArchive ar(static_cast(&mf), CArchive::store);
object->Serialize(ar);
ar.Flush();
mf.Flush();
long archive_length = mf.GetLength();
// allocate a safe place for the file
char* pbuff = new char[archive_length];
// now copy the file
mf.SeekToBegin();
// Yes, this is slow but it does prevent leaks
mf.ReadHuge(pbuff, archive_length);
A = SysAllocStringByteLen(pbuff, archive_length);
delete pbuff;
// this was the old, leak
// A = SysAllocStringByteLen((const char*)
// mf.Detach(), archive_length);
return A; // mf will clean up after itself now
}
|
|
|
|
 |
|
 |
Before transfering data via a BSTR, you may want to read MSDN atricle Q122289. It describes an alternative method. Also the Note at the bottom indicates that the BSTR transfer may not be a good idea
|
|
|
|
 |
|
 |
I will post an article to deal with flinging C++ objects across the network. Stay tuned :
|
|
|
|
 |
|
 |
Hi,
I have a problem in VC++. Could u please help me on that. I have created a dll in VC++ which has a function which will
return the recordset object.
HRESULT RecordSet([out, retval] CRecordset *value);
The CRecordset is an MFC class which cannot be used in the interface. So it shows error saying that it couldn't identify the type CRecordset which is mentioned above. The I included the Header file for
CRecordset, still the problem persist.
After that I changed the type to VARIANT ie
HRESULT RecordSet([out, retval] VARIANT *value);
But i couldnt assign a recordset object to value it
says that there is no acceptable conversion.
Could you please tell me how should I pass this recordset in dll. To be specific what type I have to write before the *value
Thanks in Advance
Shaj Fasul karim
Software Engginee
|
|
|
|
 |
|
 |
this is because ur idl cannot understand crecordset and that it supports only basic datatypes...
but there is an other way out.. use LPUNKNOWN* as the return type.. and clone ur recordset and then send it...
this works..
|
|
|
|
 |
|
 |
Hi,
I have to convert legacy C++ app to COM and this is a better way to do it unless the people who are complainning know a better way.
Regards
Vija
|
|
|
|
 |
|
 |
Thank you for your article it does show me how to work around a problem. A problem I am not sure everyone is aware of. Pardon me if this was the wrong format for this feedback.
If a declare a Get and Set property as taking and giving a BSTR. I will get a pair of properties like these complements of the Wizard.
BSTR CTestComXCtrl::GetSetBSTR()
{
CString strResult;
return strResult.AllocSysString();
}
void CTestComXCtrl::SetSetBSTR(LPCTSTR lpszNewValue)
{
CString str(lpszNewValue);
}
In the client app I again use the Wizard and I get two wrapper functions like this.
CString CTestComX::GetSetBSTR()
{
CString result;
GetProperty(0x1, VT_BSTR, (void*)&result);
return result;
}
void CTestComX::SetSetBSTR(LPCTSTR propVal)
{
SetProperty(0x1, VT_BSTR, propVal);
}
Now I would like to use it in the client app like a BSTR, which is reasonable because that's what it was declared to be.
void CTestComDlg::OnOK()
{
char sz[] = "Replace each blank with a null ";
int iTotalLength = strlen(sz);
for(int iCount=0; iCount < iTotalLength; iCount++) {
if(sz[iCount] == ' ' )
sz[iCount] = NULL;
}
CString str1(sz, iCount);
CString str2;
str2 = sz;
int len1 = str1.GetLength(); //Buffer lenght is 32
int len2 = str2.GetLength(); //length of first segment is 7
m_TestComX.SetSetBSTR(str1) ;
CDialog::OnOK();
}
The entire length of a buffer is 32, a BSTR should not be confused by NULLs in a string.
But no matter how it is casted by the client, the length of 32 is lost and it now has a lenght of 7.
Unless that is I use the code in this article to 'receive it' the hard way.
I wonder why the Wizard chooses a type like LPCTSTR when asked to wrap a BSTR. Data lose can occur.
|
|
|
|
 |
|
 |
Your problem may be declaring str1 and str2 as CString. CSrings are null terminated, so they chop off your bstr at the first null.
You might try using the _bstr_ and/or CComBstr classes instead of CString for str1 and str2. They will cast to a char*, but of course only up to the first null.
|
|
|
|
 |
|
 |
I have ever read an article in codeguru, it discussed the usage of BSTR. As BSTR's definition, it only contains the text string. So the marshaller could do anything that could do to a text string. For eg. translate from wchar to char.
Maybe now the marshaller doese nothing to the string, but we can't be sure it won't change in the future. In a word, I don't think it is a good way.
Johnny Xia
|
|
|
|
 |
|
 |
Not to pile on the original author, but Johnny is more right than he may realize.
One of the things the marshaller may do is byte-swap each character of the BSTR in order to account for different endian-ness on different machines. This is not good for the object on the receiving end which tries to read all its data in from the BSTR only to find things swapped.
|
|
|
|
 |
|
 |
Not only will the marshaller do endian conversion - which won't affect most Windows developers, but I believe it is allowed to do other format conversions, eg. locale.
Whether / where it actually does these or not I am not sure, but one place it must happen is 16-32bit Com/ole - because BSTRs are unicode in 32bit Ole and ANSI in 16bit.
Also, a common problem when trying to use bstrs like this is that com servers may truncate the bstr if it contains embedded nulls. Strictly speaking they shouldn't do this, but it is very easy to do accidentally, especially in VC++ where the compiler will silently cast between BSTR and LPOLESTR.
|
|
|
|
 |
|
 |
BSTRs are unicode unless you use SysAllocByteString instead of SysAllocString.
The microsoft docs says this is what should be used to transfer binary data using a BSTR.
Steven.
|
|
|
|
 |