March 2nd, 2006, 3:27 pm
QuoteOriginally posted by: NewGuy1) Can someone provide me with some guidance on string usage in c++. In the case of my previous post I know that output to VBA must be a BSTR (or should it be a CComBSTR) so I am using those for output. In the guts of my code, being that I come from a java/c# background, I use std::strings because of their ease of use. Finally the INTEX api that I am coding against requires char* for all string IO. So I'm stuck converting from BSTRs to strings to char* and it's a bit messy... there must be a better way. Any guidance on this is much appreciated.2) When returning results from a function call is it better to pass the output as a param by reference or to return output from the function. Passing output by reference seems preferable to me at this point as I can return success/fail info as the return value and data output as a parameter. I can also return multiple pieces of data this way. Is there a right or preferred method to determining which output technique to use?3) Can someone provide me with a resource (website, book, class, etc..) to give me some exposure to writing .dlls in c++. I basically want to write a library of functions for my company for commonly used INTEX calculations to be used in other applications, both c++ and vba. I think I could do this now, but if it will be done the "correct" way I doubt as I am basically stumbling my way around this process. I want to make sure I do it right the first time to both benefit my company and my career prospects Regarding #1, the "_bstr_t" class might help you out. It encapsulates the BSTR type, it contains the user-friendly operator overloads that you are are used to (+, etc), and there is an overload for (char*). Maybe give this a shot. In general, dealing with strings in COM is a headache.Regarding #2, I prefer to use the return value to return the results of the function, and then throw exceptions anytime something goes wrong.Regarding #3, you might want to write a COM dll, which would be callable from any COM-aware language (VB, C++, C#, etc). For authoring C++ COM dlls I would look into the Active Template Library -- I'm not sure if Microsoft still supports this, but I remember it being very straightforward. Microsoft has information about ATL at MSDN. If you are using managed C++ you could write a .NET dll and then expose it as a COM dll (interop?).- Rob