|
The problem is due to ',' in '1,000'. Remove ',' and it would work.
|
|
|
|
|
You need to parse the string to remove non-numeric characters before trying to convert it. The string is only allowed to follow a specific pattern, as described here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I could be wrong here, didn't verify yet, but using the setlocale to LC_NUMERIC for US English shoul make it recognize the thousand seperator as well.
Always consider that there are languages (mine included) that use a different decimal seperator.
Cheers, AT
Cogito ergo sum
|
|
|
|
|
If you look at the link I provided you can see which characters may be accepted.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi All,
I have to retreive the full path of the COM Dll (named "MyDllCom") from an other Exe.
How do this ?
|
|
|
|
|
If you know the CLSID of the component, you can get the DLL path from the value of the registry key HKEY_CLASSES_ROOT\CLSID\<CLSID of COM>\InprocServer32\(Default) .
|
|
|
|
|
Back on form I see!
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
|
Hello,
I've started moving a MFC MDI application from VS2005 to VS2010 (used the samples Visual C++ 2008 Feature Pack as source) and got some problems with the menu now using CMFCMenuBar.
Normally all the menu items are customizable by the user, but I want to protect the main menu items File, Edit, View, Help, ... from user customizing and only allow the user to add his own main menu(s) to the menu bar.
I thought using CMFCToolBarButton::SetProtectedCommands but that doesn't help for the main items, for the sub menu items this works.
I found also out that I could add the 0 with the call lstProtectedCmds.AddTail( (UINT)0 ); to the protected commends but this prevents the menu bar completely from customizing and the user isn't able to add his own menu to the bar any more.
Any help or ideas are welcome.
Thanks,
Andreas.
|
|
|
|
|
Hi All,
How to reyurn char* in c++? My code is
extern "C" char* callFunction()
{
std::string stroutput = pObject->ProcessNumber("hi","hi");
char* strout = new char [stroutput.size()+1];
strcpy (strout, stroutput.c_str());
return strout;
delete[] strout;
}
Thanks in advance...
G.Paulraj
|
|
|
|
|
What you've done is almost correct.
2 things are not right.
First, you cannot use extern "C" if you're using std::string because string is an object of the basic_string class.
class is not understood by C.
Second, you cannot delete the memory inside the function.
Deletion has to be done by the caller.
Also there is no point in having any statements after the return statement.
|
|
|
|
|
«_Superman_» wrote: First, you cannot use extern "C" if you're using std::string
The extern "C" merely prevents name decoration of exported function or variable names, it has nothing to do with the underlying C++ code, which may use any classes internally.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
You're right. My mistake.
|
|
|
|
|
«_Superman_» wrote: My mistake.
The first I've seen from you; you must be having a bad day!
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
The worst. !!!EVER!!!
Need to cool off . Going to the bar.
|
|
|
|
|
The delete[] will never execute, because you are return ing before you get to it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard and Superman,
Thanks for your reply.
Actaully i supposed to return std::string.
The thing is, this is a dll. and i am calling this dll from c# application.
If i return like
return "some value";
this is working fine. but if i return like,
char* str; or std::string str;
return str;
the output is not coming correctly.
from c# i am calling like
String str = somefunctionname();
How can solve this issue?
G.Paulraj
|
|
|
|
|
Since you're doing interop, you should return a BSTR .
So you will need to use the SysAllocString API on the string to convert it to BSTR .
|
|
|
|
|
First of all, if your function is part of a DLL called from outside that DLL, then memory allocated inside your function may not be released by the caller!
The reason is that the caller may not use the same memory mapping and therefore cannot manipulate the heap form your DLL.
There are various ways around that:
1. the easiest is to provide a release function in addition to your original one. The only pupose of that function is to release the buffer you previously allocated, and the caller of your function should call it once it doesn't need your string anymore.
2. A somewhat better solution, and in fact widely used, is to add another parameter to your function: a string buffer that the caller must pass to your DLL, so cou can copy the resulting string into it. Of course you must verify the buffer is big enough or else issue an appropriate error or warning. You couls also provide an additional function that simply returns the size you require the buffer to be, so the caller could first call this function, then allocate the memory and pass the resulting buffer to your function.
3. There are other ways, such as using Shared memory, but I think that would be overkill.
Here's a suggestion based on variant 2 above:
extern "C" std::size_t requiredSize();
extern "C" std::size_t getString(char* buffer);
char mystring[] = "hello world"; std::size_t requiredSize() {
return sizeof(mystring) / sizeof(char); }
std::size_t getString(char* buffer) {
if (!buffer) return 0; strcpy(buffer, mystring); return requiredSize(); }
And here's how to use it from C++:
#include "yourfile.h"
void foo() {
std::size_t sz = requiredSize(); char* mybuffer = new char[sz]; getString(buffer); puts(buffer); delete [] buffer; }
|
|
|
|
|
#include <stdio.h >
char *return_Char_Pointer(char *ptrChar)
{
ptrChar = "hello hi! I am returning a return char pointer (char *p)\n\n";
return ptrChar;
}
int main(int argc, char* argv[])
{
char *ptrChar = new char[255];
char *ptrChar1;
ptrChar1 =return_Char_Pointer(ptrChar);
printf("%s",ptrChar1);
delete []ptrChar;
return 0;
}
|
|
|
|
|
Are you posting bad code to set the enemy on the wrong track?
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]
|
|
|
|
|
You'd better use memcpy to copy the literal string to ptrChar. Doing it like the makes you call delete on statically allocated memory.
The assignment just returns the address of the literal string
Cheers, AT
Cogito ergo sum
|
|
|
|
|
I am surprised this will compile given the 'delete' is unreachable.
Anyway, just remove the delete and return strout to the caller. It is then the callers responsibility to free the memory.
==============================
Nothing to say.
|
|
|
|
|
Good one; make sure that you set the comiler warnings to max (4) and warnings as errors. That will at least make sure that something like this won't even compile.
Cheers AT
Cogito ergo sum
|
|
|
|