|
What does the following C++ application ouputs
int _tmain(int argc, _TCHAR* argv[])
{
BSTR returned_string;
returned_string = ReturnString2Vb();
wprintf( L"%s\n", returned_string);
printf("%s\n", (const char *) returned_string);
return 0;
}
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]
modified on Saturday, October 18, 2008 9:22 AM
|
|
|
|
|
well it outputs "????????????" in the console window but not the string !
thanks !
ganralf
|
|
|
|
|
Well, I'm very sorry I misread your SysAllocStringByteLen call (as SysAllocString ) . I've fixed my previous reply, please have a look at.
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]
|
|
|
|
|
thanks Pallini,
that's it now it works ! I have changed the application code as follows:
BSTR ReturnString2Vb(void)
{
char* str = "This is a test string...";
return SysAllocStringByteLen(str, strlen(str));
}
int _tmain(int argc, _TCHAR* argv[])
{
char* returned_string;
returned_string = (char *)ReturnString2Vb();
return 0;
}
again thanks for your help !
ganralf
|
|
|
|
|
You're welcome.
BTW don't forget to call
SysFreeString(returned_string);
when you no loger need it.
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]
|
|
|
|
|
ganralf wrote: f I try to use the same function in a C++ project it returns garbage !
How are you determining that it returns garbage?
From the SysAllocStringByteLen() docs:Takes an ANSI string as input, and returns a BSTR that contains an ANSI string. Does not perform any ANSI-to-Unicode translation. It's a safe guess that code that takes a BSTR expects the string to be in UTF-16. Use SysAllocString() instead.
|
|
|
|
|
Hi Michael,
thanks for your reply !
I tried SysAllocString and it works fine within a C++ project but if I try to return the string in Excel VBA it returns "T h i s i s a t e s t s t r i n g . " (every sign in the string is separated by a sign that cannot be displayed) and in VB it returns "T"
C++ dll function code
BSTR __stdcall ReturnString2Vb(void)
{
return SysAllocString(L"This is a test string.");
}
VB code
Private Declare Function ReturnString2Vb Lib "C:\testdll.dll" () As String
Function ReturnString() as string
Dim returned_string As String
returned_string = ReturnString2Vb()
end function
what am I doing wrong ? when I am using SysAllocStringByteLen all is working fine !
thanks for your help !
ganralf
modified on Sunday, October 19, 2008 7:58 AM
|
|
|
|
|
I have a section of shared memory divided into 4 areas, but I would like to use memcpy() to update each section without affecting the other section.
I have a pointer memPtr;
int *memPtr;
Can I just use:-
memscpy(memPtr, sizeof(section[0]), section[0]);
and then
memcpy(memPtr + sizeof(section[0]), section[1]);
i.e. the total ares is
MyStruct section[4]; and would like to update section[0] and section [1] as required
Thanks,
Andy.
|
|
|
|
|
I wrote a small "Hello World" program that compiles and runs well on the machine I compiled it on (running Vista). The .exe file didn't run on a different XP machine however. I learned about vcredist_x86, but I wanted my program to run on just copying it without having to "prepare" the target machine. I decided to go for static compilation since the program I am working on (not the "Hello world", btw) is small and simple enough, and doesn't need the latest and greatest lib updates.
When I change the compiler code generation runtime library option to /MT and try to build, I get a bunch of errors -
>Linking...
1>hello.obj : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: void __thiscall std::basic_ios<char,struct> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: class std::basic_streambuf<char,struct> > * __thiscall std::basic_ios<char,struct> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: class std::basic_ostream<char,struct> > & __thiscall std::basic_ostream<char,struct> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: class std::basic_ostream<char,struct> > * __thiscall std::basic_ios<char,struct> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: char __thiscall std::basic_ios<char,struct> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>hello.obj : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct> >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcpmtd.lib(cout.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<char,struct>,class std::allocator<char> >::operator*(void)const " (??D?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEABDXZ)
1>libcpmtd.lib(stdthrow.obj) : error LNK2001: unresolved external symbol __CrtDbgReportW
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(_tolower.obj) : error LNK2019: unresolved external symbol __calloc_dbg referenced in function __Getctype
1>C:\Users\Shankar\Documents\Visual Studio 2005\Projects\hello\Debug\hello.exe : fatal error LNK1120: 4 unresolved externals
1>Build log was saved at "file://c:\Users\Shankar\Documents\Visual Studio 2005\Projects\hello\hello\Debug\BuildLog.htm"
1>hello - 23 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
All this for a small "Hello World" program that uses only cout.
I tried building it with Visual Studio 2005 as well as Visual C++ 2008 Express and I get the same errors.
Can anyone let me know what I am supposed to do? Thanks.
Shankar
|
|
|
|
|
ok, after cleaning up the build, I got unresolved external symbol errors for __CrtDbgReportW, symbol __malloc_dbg, symbol __free_dbg, symbol __calloc_dbg. Are there any libraries I need to include manually?
Also I get a warning message -
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
but when I do that, I get too many unresolved symbol errors.
Thanks.
Shankar
|
|
|
|
|
When I try to make changes to my code while debugging and recompile, I get this error:
Compiling...
'~vcecho!' is not recognized as an internal or external command,
operable program or batch file.
Error executing ~vcecho!
This doesn't error happens only in one particular project. On other projects, I have no problems using edit and continue. I really like being able to fix code while I'm debugging, but on this project I can't.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
i have two buttons in a dialog box. i could not take the control from one button to another using keyboard. it's working fine with mouse Lbutton click.
could any one come up with the reason, please.
|
|
|
|
|
Hi,
You better use Tab key.
Set the Tab order using Ctrl+D in the Dialog resource.
The price of anything is the amount of life you exchange for it.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
Did you set tab for your controls on the dialog?
|
|
|
|
|
Hi all,
I want to store bmp from urls by using URLDownloadToFile..
for example I want to store urlicon of www.yahoo.com by using http://www.google.com/s2/favicons?domain=www.yahoo.com
This url gives me the Yahoo icon.
Now I want to store this so I have used URLDownloadToFile, and It get stored also .
but by using LoadImage, I couldn't load this stored image.
Please suggest me solution or some other way of downloading fevicons of urls.
Thanks in advance.
|
|
|
|
|
I dont know you asked this question previous or no but you must be extract controls on the web page and on the codeproject we have a simple for it.
|
|
|
|
|
What error is LoadImage() returning?
|
|
|
|
|
Thanks for reply..
I have resolved the problem.
Sorry for delay in reply..
|
|
|
|
|
|
Hi,
There is no way to make the maximize box invisible if you have minimize box.
If you dont want the minimize box also. Then use
cs.style &= ~WS_MAXIMIZEBOX;
cs.style &= ~WS_MINIMIZEBOX;
Now only you will get window without Maximize box and Minimize box.
The price of anything is the amount of life you exchange for it.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
Hi,
I would like to store a word in a string array. here is my code:
cArray = new char[str.GetLength()+1]; //here actually store the words that I key in the edit control.
Str1[100];
when the program detect the "space" it will store the previous character that had been read. For example: i have the code to read the character 1 by 1. But then im unable to store the "how" word in an array. I will only store the "h" instead of full words. Is there any code to advice? thank you.
|
|
|
|
|
Could you post the code you've written so far?
BTW Do you know CString exposes the PCXSTR operator [^]?
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]
|
|
|
|
|
actually here is my code to read the text that i write in the edit control.
CString str = m_sText1;
char *cArray = NULL;
int g = str.GetLength();
cArray = new char[str.GetLength()+1];
strcpy(cArray, LPCTSTR(str));
CString word[20];
CString str1[20];
int c=0;
int a=0;
for(int i=0; i<g; i++)
{
if(i!=(g-1))
{
if(cArray[i]!= ' ')
{
word[c]=cArray[i];
c++;
}
else
{
str1[a] = word;
a++;
}
}
m_Text1 = str1[0];
}
here is the code. But i don know how to store the word. it will just store 1 by 1. Maybe my code is wrong. Thank you for answering me
|
|
|
|
|
If you need to separate words, using the ' ' character, then I suggest you using CString::Tokenize method, in its documentation page [^] there is a code sample very close to such requirement.
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]
|
|
|
|
|
Hi Pallini,
Thx a lot..... Thx a lot... Im able to load the words. Need to modification then i can load the word into string array. As i need to pass the words that i read to go into other function. Thx a lot....
I try to do it now.. If later i success then inform u..
|
|
|
|