Oen
asked on
COM-ATL data type which should look like "as any"
Hello to everybody
I try to make a type library and i need to get the address(and use in C++ functions) of any type of variables from Visual Basic.Because MIDL restricted the usage of the void type i don't understand which data type i should to use to be in Visual Basic like "as any" and to be able to use any kind of variables type.
THX
I try to make a type library and i need to get the address(and use in C++ functions) of any type of variables from Visual Basic.Because MIDL restricted the usage of the void type i don't understand which data type i should to use to be in Visual Basic like "as any" and to be able to use any kind of variables type.
THX
You should use VARIANT data type. If you use MFC you may find it's easier to work with COleVariant class than with VARIANT directly.
ASKER
I already trying and is not working.I can encapsulate data and passed to C++ type library on the VARIANT but with the memory address is a problem.
I need to be something equivalent with the void type.I must to be able to take the address of any kind of variables (which is used like parameter) from VB,.NET,C#
THX
I need to be something equivalent with the void type.I must to be able to take the address of any kind of variables (which is used like parameter) from VB,.NET,C#
THX
How do you allocate memory for VARIANTs?
Try VariantInit()
if you are passing any objects or strings in the variable, it should reside in the global heap.
For strings you can use SysAllocString and pass that pointer to the variant.
Try VariantInit()
if you are passing any objects or strings in the variable, it should reside in the global heap.
For strings you can use SysAllocString and pass that pointer to the variant.
ASKER
ok.It seems that is time to explain a little more what i wish to try.
In fact i should get pointers from some variables from VB.If i use VARIANT ,for example, how can i will be able to use a pointer from an UNICODE string(VB way) and using to a char*(C++ way) ?
And after this to handle data from VB using the C++ pointers.
That is my problem.For this reason i need the void type.
I saw some IDL(from Development Studio) files and i understand that is possible.But i don't have too much experience with ATL and i don't know how is possible to avoid the MIDL 2139 error(that means can not be used data type which are from void or void* type)if in the MSDN is written that is not applicabile.
THX
I increase up to 300 points.
In fact i should get pointers from some variables from VB.If i use VARIANT ,for example, how can i will be able to use a pointer from an UNICODE string(VB way) and using to a char*(C++ way) ?
And after this to handle data from VB using the C++ pointers.
That is my problem.For this reason i need the void type.
I saw some IDL(from Development Studio) files and i understand that is possible.But i don't have too much experience with ATL and i don't know how is possible to avoid the MIDL 2139 error(that means can not be used data type which are from void or void* type)if in the MSDN is written that is not applicabile.
THX
I increase up to 300 points.
Basically, you can do i t like this, all sanity checks are omitted. You should check the type of the variant and act accordingly. Here I assume it's a string.
STDMETHODIMP CTest::TestMethod(VARIANT data)
{
// ATL provides macros A2W and W2A for conversion
USES_CONVERSION;
char* x = W2A(data.bstrVal);
MessageBox(0,x,"Hi",0);
// You have to release the string (or reallocate it if the parameter is [in, out])
SysFreeString(data.bstrVal );
return S_OK;
}
STDMETHODIMP CTest::TestMethod(VARIANT data)
{
// ATL provides macros A2W and W2A for conversion
USES_CONVERSION;
char* x = W2A(data.bstrVal);
MessageBox(0,x,"Hi",0);
// You have to release the string (or reallocate it if the parameter is [in, out])
SysFreeString(data.bstrVal
return S_OK;
}
ASKER
Thank you very much about info.I know what can be done with the VARIANT type.Other way to convert is to using _bstr_t.
But i'm very interested about how can be used the void type with MIDL.
Thank's again.
But i'm very interested about how can be used the void type with MIDL.
Thank's again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the way to use void data type in automation.So , the topic i will close and the points will be for the aleksoft.