|
Hello !
I have a dll written in C++ that is used in a VB application. In one function, I send a string (BSTR type, so it has the VB format), and I want to convert it into a char* string. How can I do that easily ?
Thank you.
|
|
|
|
|
I think you can do this
<br />
BSTR temp;<br />
char* str = (char*)_bstr_t(temp);<br />
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Ok thanks, I will try this
|
|
|
|
|
The BSTR Value is UNICODE Value, you should use a routine to convert from Unicode to ANSI.
Using cast method, you can lose data, and you can have memory leaks.
The best way to do it is :
USES_CONVERSION
char* a = W2A(bstrvalue);
IMHO you should use UNICODE type, like wchar ao rather than char.
To prevent to have 2 types, you can use TCHAR.
regards
Rodrigo Pinho Pereira de Souza
|
|
|
|
|
I do this:
m_valueSearchBox.SetWindowText(initValue);
if I do this the initValue string (CString) wil be selected, but I need the cursor behind the text so you can type an appending text.
SetSel doesn't seem to work?
tnx.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
Why shouldn't it? Try this:
CString str;<br />
m_valueSearchBox.GetWindowText(str);<br />
int nPos = str.GetLength();<br />
m_valueSearchBox.SetSel(nPos, nPos, TRUE);
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
tnx for the reply, but I'm afraid I must dissapoint you.
I do this:
<br />
int pos = initValue.GetLength();<br />
m_valueSearchBox.SetWindowText(initValue);<br />
m_valueSearchBox.SetSel(pos, pos, TRUE);<br />
(it's SET not GET, but not important).
What happens is that the cursor is behind the text, BUT the text is selected, so if you start typing ...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
V. wrote:
m_valueSearchBox.SetSel(pos, pos, TRUE);
I think the positions in SelSel are index based, so try:
m_valueSearchBox.SetSel(pos-1, pos-1, TRUE);
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
tnx for your reply, but I have to disappoint you too.
I tried SetFocus() and SetSel with about every value possible.
SetSel(-1, nPos, FALSE/TRUE); (nPos = length, length-1 ,... as first and/or second parameter etc.)
It just doesn't seem to work.
Normally it should, but maybe it's due to something else (processor or something)
I don't know, I'll keep searching
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
It must be something other then.
I tried this in a test project:
CString str = _T("Test");<br />
m_cEdit.SetWindowText(str);<br />
int nPos = str.GetLength();<br />
m_cEdit.SetSel(nPos, nPos, TRUE);<br />
m_cEdit.SetFocus();
And it does exactly what you want. "Test" is written into the edit control and the cursor is at the end, nothing is selected.
Maybe check for other things that could influence the selection and focus (UpdateData, returning FALSE in OnInitDialog, and all those things)
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
The correct answer:
<br />
m_valueSearchBox.SetWindowText(initValue);<br />
int nPos = initValue.GetLength();<br />
m_valueSearchBox.SetSel(nPos, nPos, TRUE);<br />
m_valueSearchBox.SetFocus();<br />
bResult = FALSE;<br />
bResult is returned in OnInitDialog. So you were right.
Huge tnx to you. (and off course all others who tried to help )
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
Hi All, On win2000 I have created an exe file to list and load dll files. Selecting a dll should load an API file, also a dll. LoadLibrary() works in the exe but not in a dll. Can anyone tell me what's wrong?
D. Kelly
|
|
|
|
|
Not sure. You must be doing something wrong in your DLL, because any DLL could really load another DLL.
When you call the LoadLibrary, what is the return value from GetLastError when the LoadLibrary fails? That is a good clue what is wrong.
|
|
|
|
|
My mistake Blake, I should have finished the story.
The .dll API file is in the root directory of D:.
The LoadLibrary("D:\\wrk32.dll")result is picked up by GetLastError() which is 126, file not found.
|
|
|
|
|
Just before loading your DLL, add this line of code to your program:
SetErrorMode(0);
That way, when you run your progrma, a dialog box will pop up and you can see which DLL is missing. It will tell you all the places it tried to load the missing DLL.
Make sure to take the call back out before releasing your program.
|
|
|
|
|
Thanks very much. That tip was most helpfull.
Daniel Kelly
|
|
|
|
|
Where can i find an online VC++ 6 macros reference (the VB macros)?
|
|
|
|
|
IIRC there's a reference in the VC++ 6 installed Help.
Kevin
|
|
|
|
|
Im getting tired of people telling me whats on the VS6 cd's if had them why would i ask the question?
(im sorry to sound hatefull but its getting annoying)
thats why i specified "online" meaning "located on the internet"
|
|
|
|
|
I assumed that if you were running VC++ you would have had the Help installed? But that's not always so.
However, you can also always find an up-to-date Help set, which is a superset of the Visual Studio installed online help, at http://msdn.microsoft.com/library[^].
The macros reference will be in there somewhere. Though I always find the online version of the MSDN Library harder to search than the installed version.
Kevin
|
|
|
|
|
I just started COM programming and managed to write some small sample programs to use the IActiveDesktop and IShellLink interfaces and their methods; basically i am playing around with things like these for the time being:
<br />
CoInitialize(NULL);<br />
<br />
WCHAR wszWallpaper [MAX_PATH];<br />
HRESULT hr;<br />
IActiveDesktop* pIAD;<br />
<br />
<br />
hr = CoCreateInstance ( CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**) &pIAD );<br />
<br />
if ( SUCCEEDED(hr) )<br />
{<br />
hr = pIAD->GetWallpaper ( wszWallpaper, MAX_PATH, 0 );<br />
<br />
if ( SUCCEEDED(hr) )<br />
{<br />
wcout << L"Wallpaper path is:\n " << wszWallpaper << endl << endl;<br />
}<br />
<br />
}<br />
<br />
The above compiles correctly and works successfully.
However, when i try to use the ITaskbarList in the same manner, the compiler throws it all up, telling me that ITaskbarList is an undeclared identifier...
Any ideas where i'm getting it all wrong?
Many thanks...
Chris
|
|
|
|
|
Hi,
I wanted to create dynamically controls (CButton) on my dialog. They are displayed but don't react. Second problem is that I want to react in the dialog to a click on a button.
The creation of buttons (this -> the dialog containing the buttons)
for (int i = 0; i < 16; i++)
{
pButton = new CButton;
iLeft = (iWidth+iSpace)*i;
pButton->Create(_T(""), WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,
CRect(iLeft,10,iLeft + iWidth,30), this, WM_USER+i);
}
But now I don't know how to get the message queue of the buttons!
thx & greets
|
|
|
|
|
You can either specify an ON_COMMAND_RANGE handler for all of them at once, or add buttons in the resource editor with the desired id, create handlers and them remove the buttons (but not the handlers, of course)
|
|
|
|
|
ok thank you!
But what I wanted to know is how to create buttons at runtime.
so the problem is that I cannot set ON_COMMAND_RANGE handler cause I don't know how many buttons there will be. But every button should react the same way!
greets
|
|
|
|
|
You can use ON_COMMAND_RANGE anyway, just allow for the max number of buttons.
|
|
|
|