|
Of course VB6 takes care of performing the opposite conversion (you know, that language was highly engineered... ).
However that doesn't happen on the function return value but on passed parameter (I need to update the reply to the OP).
From the same MSDN article (did you read it?):
void __stdcall FillString(LPSTR pszString, LONG cSize)
{
char buffer[] = "Hello from the C DLL!";
if (cSize > strlen(buffer))
strcpy(pszString, buffer);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanx. but if i want to change this function for unicode what changes have to be done, so this function supports unicode.
gold
|
|
|
|
|
I suppose you should make a COM component.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The problem you try to solve is passing a string to a caller, where the caller has no knowledge of the length of that string, and therefore cannot easily provide a buffer variable to store that string into.
The posted solution does not work, because the compiler will create a local copy of the string literal you used for initialization, and the address to that copy will be invalidated upon return.
If you used const wchar_t* instead of wchar_t* , and the appropriate const string types, it might have worked. But if you want a non-const string, then there are really only two possible ways to deal with this:
1. use a secondary function that enables the caller to inquire about the expected length of the string, and then pass a buffer of sufficient size to DisplayInfo.
const wchar_t* HELLO = _T("Yahoooooo");
int DisplayInfoSize()
{
return wcslen(HELLO);
}
LPCWSTR __stdcall DisplayInfo(wchar_t* hello)
{
return wcscpy(hello, HELLO);
}
2. Have DisplayInfo allocate memory on the heap to story that string.
const wchar_t* HELLO = _T("Yahoooooo");
LPCWSTR __stdcall DisplayInfo()
{
wchar_t* hello = new wchar_t*[wcslen(HELLO)+1];
return wcscpy(hello, HELLO);
}
Solution 1 is awkward, but it makes sure the caller can release the allocated memory once the string is no longer needed. Solution 2 might create a memory leak, if the caller has no way to properly release the string being passed to it (which may very well be the case if it's called from VB), but it would not require a change of the interface.
P.S.:
Just realized that the return type on your DisplayInfo function is a const string! This means that the compiler should indeed just return a pointer to the literal as others already pointed out. I'm sorry, I got confused by the cast in your return statement (which is non-const string!)
The suggestions above might still work if none of the other responses are helping.
modified on Monday, January 10, 2011 6:34 AM
|
|
|
|
|
hello guys... When I craete a NEW solution in VS 2008 and choose the solution combo box as "Add to the Solution", only then I can add a reference (a dll reference). But If I create a solution and choose the solution combo box as "Create New SOlution", it does not show me the required reference even after providing all the necessary paths. How can I add the reference when I choose the "Create a New Solution"??
|
|
|
|
|
I want to ask you something ( maybe ) simple question :
Can I initialize an CListBox& ListCtrl reference with null value ? Because later , I want to use ListCtrl reference variable in many if contitions ...
I try :
CListBox& ListCtrl = NULL;
and doesn't go ...
Give me an error like this :
initializing' : cannot convert from 'const int' to 'class CListBox &'
|
|
|
|
|
Hi,
You are trying to initialize a reference to CListBox, in which case you need to give proper object. NULL is nothing but a typedef of '0'. To solve your problem try to use a pointer variable instead of reference variable.
CListBox *pListBox = NULL;
|
|
|
|
|
I can use CListBox* pList = NULL;
Why , because somewhere I have :
CListBox& GetListBoxCtrl() const {return *(CListBox*)this;}
How can I solve the problem ?
|
|
|
|
|
You cannot assign NULL to a reference.
In your case you can do this - CListBox* pListBox = &GetListBoxCtrl();
|
|
|
|
|
Nope.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
I open an notepad application :
void CTestMessageView::OnHelpStartapplication()
{
ShellExecute(m_hWnd,"open","notepad.exe",NULL,NULL,SW_SHOWNORMAL);
}
and I want to send some message to notepad :
void CTestMessageView::OnHelpSendmessage()
{
CString sTemp = "Test message\n";
HWND hWnd = ::FindWindow("Notepad",NULL);
if(hWnd)
{
::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
::PostMessage(hWnd,WM_KEYDOWN,'1',0);
::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
}
}
but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?
modified on Saturday, January 1, 2011 9:13 AM
|
|
|
|
|
Do an EnumChildWindows[^] on your hWnd and locate the edit control
Regards
Espen Harlinn
|
|
|
|
|
What exactly are you trying to do here?
Opening notepad and then sending it a WM_CLOSE does not make sense.
Notepad also takes a command line parameter if you want to open a file in it.
For eample - notepad.exe c:\windows\win.ini
|
|
|
|
|
I think he's trying to open Notepad and insert some text (the sTemp string.)
What he's found is 4 ways to insert text which do not work, and also found that sending a WM_CLOSE does work. It's a start.
|
|
|
|
|
you can't just pass pointers from one process to another process; they must be meaningful and accessible for the receiver, and in general buffers at the sender are neither to the receiver. It would take some calls to VirtualAllocEx, WriteProcessMemory, and the like to achieve such things.
But then, why would you? if you want to open Notepad on an empty document and then "type" some, why not simply create a text file first, then open it with Notepad? You wouldn't need any Win32 API function to do that.
|
|
|
|
|
hi
how can i have nested groups in a CPropertyGridCtrl without increasing indent?
let me depict what i'm going to do. i've a ready program with the following output:
original[^]
i tried to create the same output with the following code:
void AcItemPropertyPane::pr_appendLinkProp(CMFCPropertyGridProperty *pGroup, const AsLink &link)
{
CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty("Coordinate for Goto", 0, TRUE);
CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty("Address X", (_variant_t) link.col, " ");
pProp->EnableSpinControl(TRUE, 0, 99);
pGroup2->AddSubItem(pProp);
pProp = new CMFCPropertyGridProperty("Address Y", (_variant_t) link.row, " ");
pProp->EnableSpinControl(TRUE, 0, 9);
pGroup2->AddSubItem(pProp);
pGroup->AddSubItem(pGroup2);
pProp = new CMFCPropertyGridColorProperty("Color of Goto Route", (_variant_t) link.color, NULL, "Goto line color change");
pGroup->AddSubItem(pProp);
}
void AcItemPropertyPane::pr_initADSensorPropList(const AsItemSpec &is)
{
d_wndPropList.RemoveAll();
CMFCPropertyGridProperty *pGroup = new CMFCPropertyGridProperty("AD Setup");
CMFCPropertyGridProperty *pProp = new CMFCPropertyGridProperty("A/D port", " ", "A/D port setup");
pGroup->AddSubItem(pProp);
pGroup->AddSubItem(pr_newFuncProp(is.func));
pProp = new CMFCPropertyGridProperty("Compare variable/value", " ", "When jump is compare to Input value (0-255).");
pGroup->AddSubItem(pProp);
pr_appendLinkProp(pGroup, is.link);
d_wndPropList.AddProperty(pGroup);
}
(pr_initADSensorPropList is called).
but it resulted in the following output:
mine[^]
there's also a difference in the original color property and mine. also separator in coordinate differ (; with ,)
how can i make mine appear the same as the original one?
thank u
|
|
|
|
|
Index is removed from msdn by default in visual studio 2010. Although there are some plugin, but not as good as in VS2008.
BTW, when opening and running two or more instances of VS2008, the UI will be out of order. For example,
running a server and a client in two instances of VS2008, when one aborted, one of the UI became out of order, I don't remember which.
What's like, the index in mysql document is also removed.
============
If search works, it is also possible to build an index only once instead?
I think M$ is collecting in the search procedure for analysis, for its bing.com.
modified on Sunday, January 2, 2011 9:47 PM
|
|
|
|
|
Is this a question about C++, or simply a rant about Microsoft?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
about its programming environment
modified on Saturday, January 1, 2011 9:57 PM
|
|
|
|
|
Hi
I have created the event using CreateEvent Method. But I am not able to open this event using ::OpenEvent () method from RTOS Application. Do I need to create the event by setting some security level in first parameter of CreateEvent ().
Thanks
|
|
|
|
|
the security parameters can be NULL. its ok. CreateEvent will the use the default level of security.
To use openevent function you must have to create a named event. Did you created event like that ?
If u can Dream... U can do it
|
|
|
|
|
Yes I have created the Named event . I have Opened this event successfully and used in another win32 process. As I am trying this with RTOS , not able to find out why my RtOpenEvent fails.
::RtOpenEvent and ::OpenEvent both are supported in my RTOS SDK. I have also tried to use Global\\MyEventName .
Thanks and happy New Year
|
|
|
|
|
I don't know about RtOpenEvent , but this is what I would do if OpenEvent fails.
I would first check its return value to find that it failed.
I would then call GetLastError to find out why the API failed.
You should have something similar for the RTOS APIs.
|
|
|
|
|
hmm, sharing events betwen processes... its been a long time since i did usermode stuff but is it even possible?
"It is a remarkable fact that despite the worldwide expenditure of perhaps US$50 billion since 1990, and the efforts of tens of thousands of scientists worldwide, no human climate signal has yet been detected that is distinct from natural variation."
Bob Carter, Research Professor of Geology, James Cook University, Townsville
|
|
|
|
|