|
Great!
sorry, this was really clear, it's my fault, tonight I haven't sleeped and I'm very tired
thank you very much!
|
|
|
|
|
How do I convert a CString to a _bstr_t?
Thanks,
ns
|
|
|
|
|
_bstr_t bstrText = L"text";
CString strText = (LPCWSTR)bstrText;
CString strText2 = (LPCSTR)bstrText;
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
The other way round:
I have CString a ="abc";
I want to make this a _bstr_t, so that I have:
_bstr_t ab = SOmethingDoneTo (a)
Thanks,
ns
|
|
|
|
|
Incidentally, whats the L mean here from your snippet?
L"text";
Thanks,
ns
|
|
|
|
|
To answer both of your questions:
ns wrote:
Incidentally, whats the L mean here from your snippet?
It means that the hardcoded text shall be interpreted as a string of wchar - not char. In other words:
char* pszText = "this is a text";
wchar_t* pszwText = L"so is this";
char* pszText2 = L"doesn't work";
wchar* pszwText2 = "doesn't work either"
To answer your other question - to convert from CString to _bstr_t you can use:
CString strText = _T("This is a text");
_bstr_t bstrText = (LPCTSTR)strText;
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Here is a code fragment:
void CShelf2Dlg::OutStr(CString Str, int Port)
{
VARIANT va;
va.vt = VT_BSTR; // The variant is storing a string
va.bstrVal = Str.AllocSysString(); // Convert the CString to the VARIANT
Comport[Port]->SetOutput(va); // and output it
}
Elaine (fluffy tigress emoticon)
Would you like to meet my teddy bear ?
|
|
|
|
|
Well, I did
_bstr_t b_dataBaseName = SysAllocString (dataBaseName);
where dataBaseName is a char* and get the error:
error C2664: 'SysAllocString' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
Thanks,
ns
|
|
|
|
|
This will work but your program will leak memory. ::SysAllocString allocates a BSTR and you are assigning it to a _bstr_t. _bstr_t does not take ownership of the BSTR however so you would have to release it using ::SysFreeString( ).
Yet another way would be to use the USES_CONVERSION macros defined in atlconv.h - your code would then look like:
USES_CONVERSION;
_bstr_t b_databaseName = T2W( dataBaseName );
Hope this helps,
- d a b s -
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
I tried both your ideas, (freeing the bstr also), but I got from the atlconv idea:
error C2664: 'MakeDB' : cannot convert parameter 1 from 'class _bstr_t' to 'unsigned short ** '
I must be doing something incredibly dumb....
char* dataBaseName = new char[dataBaseName0.GetLength() +1];
strcpy(dataBaseName, dataBaseName0);
USES_CONVERSION;
_bstr_t b_dataBaseName = T2W( dataBaseName );
char* strFile = new char[strFile0.GetLength() +1];
strcpy(strFile, strFile0);
_bstr_t b_strFile = T2W(strFile);
_Class1Ptr ptr;
ptr.CreateInstance(__uuidof(Class1));
ptr->MakeDB( b_strFile, b_dataBaseName);
delete[] etc
Thanks for all the help so far....
Thanks,
ns
|
|
|
|
|
This is probably the easiest way to do it:
USES_CONVERSION;
LPCWSTR pszwDatabaseName = T2W( (LPCTSTR)dataBaseName0 );
LPCWSTR pszwFileName = T2W( (LPCTSTR)strFile0 );
_Class1Ptr ptr;
ptr.CreateInstance(__uuidof(Class1));
ptr->MakeDB( pszwFileName, pszwDatabaseName );
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Did your latest idea:
error C2664: 'MakeDB' : cannot convert parameter 1 from 'const unsigned short *' to 'unsigned short **
for my VB function:
Public Function MakeDB(txtPMAFilename As String, dataBaseName As String)
why does it think vb String is 'unsigned short **' ?
I've tried so many different ideas from all the supportive replies, but seem to be stumped!
Thanks,
ns
|
|
|
|
|
I had to change the vb parameters to byval....now it compiles. May or may not run but at least it compiled! Sorry for all the bother and thanks for all the help!!!
ns
Thanks,
ns
|
|
|
|
|
SInce the resolution was to code the VB function parameter as ByVal, does this mean that _bstr_t variables can only be passed in by value? What if we wanted to change a _bstr_t variable in the VB dll so that the changes would be reflected in the VC side?
Puzzled,
Thanks,
ns
Thanks,
ns
|
|
|
|
|
How to get the handle of a previous appln window
|
|
|
|
|
Can u be more precise..
I didnt get u......
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
If you are trying to create a singleton application then this is not the best way to do it. There are articles here about this - the best one is probably by Joseph Newcomer - can't remember the URL.
If however you want to find out the handle to a previous instance of your app window you can always use ::FindWindow( ). You must know the WNDCLASS of your main window to do this and to complicate matters even more you will probably have to think about the case when there are more than one previous windows around.
Example: to find a running instance of Excel you can use:
HWND hWndExcel = ::FindWindow( _T("XLMAIN"), NULL );
Then if you want to find a window with a special window caption - say you know the Excel instance you want to find has the file "secrets.xls" open you could use this:
HWND hWndExcel = ::FindWindow( _T("XLMAIN"), _T("Microsoft Excel - secrets.xls") );
Hope this helps somewhat,
- d a b s -
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
I have a large client area, and scroll bars are needed to view it all. Using the normal code puts only the visible area in the clipboars. I need to dump the visible as well as the non-visible part of the client area on to the clipboard. Please help!!!
|
|
|
|
|
I made an app that can run on Win9x/Win2k.
I want that on Win2k my dialog become transparent, so I used the fonction SetLayeredWindowAttributes(...). It won't compile, I've added /D "_WIN32_WINNT=0x0500" to the compiler additional Options, now it compils but don't work on Win9x...
Is it a way to make my app work on all Windows ?
|
|
|
|
|
Unfortunately not... Transpareny was introduced in W2K (WinNT 5.0)
|
|
|
|
|
Yes I know, but I thought that the app can run on Win9x and the fonction simply ignored....
And I know I can load SetLayeredWindowAttributes directly from "User32.dll" with LoadLibrary blabla, but I was asking if there is a solution to simply use SetLayeredWindowAttributes (I don't need to load it from User32.dll because I have the last Platform SDK) and make my app run on all Windows (and the fonction does nothing on Win9x).
Ouch sorry for my english I hope someone will understand what I want to say ;o)
Anyway, Lakitu thanks for your answer.
|
|
|
|
|
OSVERSIONINFO os;
::GetVersionEx(&os);
if ( os.dwMajorVersion>=5 )
SetLayeredWindowAttributes(...).
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
Yes I know this code, but it doesn't solve my problem !
To compile it I have to set /D "_WIN32_WINNT=0x0500" but when I set that it doesn't work on Win9x :-/
|
|
|
|
|
Put this code in a separate DLL. And make two versions of this DLL, one without _WIN32_WINNT=0x0500. From your main app, you then just need to load the appropriate DLL depending on the os version.
This DLL remains small, which is may be a better approach than having two whole apps compiled for each target os.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
The alternative is to write a wrapper function for the one you're trying to use, which detects the OS version and if it's Win2000/XP or later, gets the address of the function from USER32 and calls it, otherwise does nothing.
Your problem is two things;
You don't have the function declaration unless you have _WIN32_WINNT set to 0x0500, and with that in place, you have a reference to the function in your EXE.
When the EXE runs on an earlier (NT,9x) system, the function cannot be located by the import lib code you pulled in when you built.
You can either do what Stephane suggests, what I suggest, or not use the function
Steve S
[This signature space available for rent]
|
|
|
|