|
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]
|
|
|
|
|
|
hi all,
can u please tell the function to get the application path in MFC
|
|
|
|
|
char strAppPath[256];
GetModuleFileName(NULL, strAppPath, sizeof(strAppPath));
|
|
|
|
|
I use follow function:
CString GetHomeDirectory() const
{
TCHAR sFilename[_MAX_PATH];
TCHAR sDrive[_MAX_DRIVE];
TCHAR sDir[_MAX_DIR];
TCHAR sFname[_MAX_FNAME];
TCHAR sExt[_MAX_EXT];
GetModuleFileName(AfxGetInstanceHandle(), sFilename, _MAX_PATH);
_tsplitpath(sFilename, sDrive, sDir, sFname, sExt);
CString rVal(CString(sDrive) + CString(sDir));
int nLen = rVal.GetLength();
if (rVal.GetAt(nLen-1) != _T('\\'))
rVal += _T("\\");
return rVal;
}
Best regards,
Eugene Pustovoyt
|
|
|
|
|
I used these set of codes
<br />
CString StrLaunched;<br />
TCHAR szFullPath[MAX_PATH];<br />
TCHAR szDir[_MAX_DIR];<br />
TCHAR szDrive[_MAX_DRIVE];<br />
::GetModuleFileName(NULL,szFullPath,MAX_PATH);<br />
_splitpath(szFullPath, szDrive, szDir, NULL, NULL);<br />
<br />
<br />
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Can I load a combo box from a id (resource id) to get a CComboBox class, like the CMenu function 'LoadMenu' ???
I want write some code like this, but with a combo box:
CMenu menu;
menu.LoadMenu(ID_MYMENU);
...
--> I want write something:
CComboBox box;
box.xxx(ID_MYBOX);
...
(Does it give any function for 'xxx' ???)
Does it give any function for CComboBox to do this ???
--
Nice greets, Daniel.
|
|
|
|
|
You can enter the combo-box selections in the resource-editor, in the properties of the combo-box control, rider 'Data'.
This is stupid IMHO, as you have one more place to work at if you need to change the combo-box.
Better load strings from the stringtable and add these to your combo-box.
So you see in your code what is added to your combobox and you keep your code free from string constatants.
|
|
|
|
|
I can't edit the properties of the combo box in the resource editor, because the combo box is not created on a dialog. The combo box is placed in a command bar and is created with the 'CommandBar_InsertComboBox' function. So, the only thing I have is the ID of the combo box. I can edit the combo box with the 'GetDlgItem' and the 'SendMessage' function, but I use the mfc and so I want use the CComboBox class. So I need a function like 'LoadMenu' for the CMenu class for the CComboBox.
(I program on a pocket pc with eVC++ 3.0)
--
Nice greets, Daniel.
|
|
|
|