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
LVL 1
OenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aleksoftCommented:
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.
OenAuthor Commented:
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
aleksoftCommented:
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.

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

OenAuthor Commented:
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.
aleksoftCommented:
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;
}
OenAuthor Commented:
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.
aleksoftCommented:
Pointers to void are not Automation compatible and can't be used with VB. In COM terms "void" means the function does not return a value, ie it is a Sub in VB's terms. "As Any" is used only in context of non COM function calls, such as Windows API functions. If this is what you want you really want to do, then throw away all COM stuff and create a regular dll and export functions you needed using stdcall naming convension. You will need then create "Declare Function" statements in VB for every function you want to use from VB. You could then use As Any, but it will probably be a hell to make it work. VB does not perform any type checking for As Any, and you'd better be sure what your "Any" really is. More likely than not, it will not be exactly what you think it ought to be. My recommendation stay with VARIANTs if you don't know in advance what data types you will pass to the function.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OenAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.