|
ahh.. great!
thanks much.
-c
|
|
|
|
|
The values 0..7F are the same as ASCII (as in most modern encodings)(with the exception of \ being replaced by ¥). If you have any character values >= 0x80, there may not be an ASCII equivalent (for example, any kana or kanji).
|
|
|
|
|
Hi Michael,
I do not fully agree, ASCII is a 7-bit character set; when represented by a larger number
(say an 8-bit byte) then the higher bit(s) must be zero.
So if another set has matching characters for value (0x00,0x7F) then all other characters
can not be represented in ASCII, unless some extension is applied; to name a few:
ANSI, MS-1252 (and all other "code pages"), UTF8, and of course Unicode.
|
|
|
|
|
Hi together,
i'm trying to pass Strings from a vb project to a c++ Dll and from the Dll back to vb in one function.
It will work from VB to the Dll but not back ?!?!?!?!
I'm trying this now for some days and i couldn't find a solution !
You are my last hope !
Here are the codes:
VB:
<br />
Option Explicit<br />
<br />
Private Declare Function fnWin32DLL02 Lib "E:\WORKING\OMRON\GDT\EigeneDLL\C++ DLL mit VB (Test01)\Win32DLL02.dll" (ByVal testParam As String) As String<br />
<br />
Private Sub Form_Load()<br />
<br />
Dim x As String<br />
x = Space$(5)<br />
Dim test As String<br />
test = Space$(20)<br />
<br />
test = "Übergabe aus VB"<br />
x = fnWin32DLL02(test)<br />
MsgBox "X ist: " & x<br />
<br />
End Sub<br />
Dll cpp:
<br />
WIN32DLL02_API BSTR fnWin32DLL02(BSTR s)<br />
{<br />
BSTR x;<br />
<br />
x = SysAllocString((BSTR)"abcde");<br />
MessageBox(NULL,(LPCSTR)s,"Info",MB_OK);<br />
<br />
SysFreeString(s);<br />
SysFreeString(x);<br />
<br />
return x;<br />
}<br />
Dll.h
<br />
WIN32DLL02_API BSTR fnWin32DLL02(BSTR);<br />
I hope it is not too much code but it is the best way to show you my problem.
Many, many thanx
hopefully
Croc
|
|
|
|
|
CrocodileBuck wrote: SysFreeString(x);
Why are freeing the (allocated) string you need to return?
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.
[my articles]
|
|
|
|
|
Thx Pallini,
for your quick answer i no freeing now
Bit it still won't work !
Thx again
Croc
|
|
|
|
|
Well I think you have to change
CrocodileBuck wrote: x = SysAllocString((BSTR)"abcde");
with
x = SysAllocString(L"abcde");
but I cannot be sure because I've not a VB6 available at the moment.
BTW what is returned to VB6?
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.
[my articles]
|
|
|
|
|
Thx again Pallini,
i've changed it but it still win't work, is some thing wrong with the vb Code ?
Here is the changed Dll.Cpp:
<br />
WIN32DLL02_API BSTR fnWin32DLL02(LPCSTR s)<br />
{<br />
BSTR x;<br />
<br />
x = SysAllocString(L"abcde");<br />
<br />
MessageBox(NULL,s,"Info",MB_OK);<br />
<br />
<br />
return x;<br />
}<br />
Many thx
Croc
|
|
|
|
|
From documentation seems that you have to pass back an ANSI string, which will be translated by VB6, i.e. try to change
CrocodileBuck wrote:
x = SysAllocString(L"abcde");
char * psz = "abcde";
x = SysAllocStringLen(psz, strlen(psz));
Again, I haven't VB6 at hand,so the attempt is up to you (I apologize for ).
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.
[my articles]
|
|
|
|
|
You can use BSTR only if you have a COM dll, which you obviously don't. So, try returning good ol char* instead.
|
|
|
|
|
Nemanja Trifunovic wrote: You can use BSTR only if you have a COM dll, which you obviously don't. So, try returning good ol char* instead.
Are you sure? If I remember it right, I've returned BSTR from a regular dll for some reason and I think it worked. I am not on my Dev machine now to verify it.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Rajesh R Subramanian wrote: I've returned BSTR from a regular dll for some reason and I think it worked.
IIRC, it is "doable" if you catch it as a byte array on the VB side, but it does not work out of the box.
|
|
|
|
|
In addition to what the other posts said, you are also misusing casts.
(BSTR)"abcde" is wrong - a string literal is not a BSTR .
(LPCSTR)s is wrong - a BSTR is not a const char* .
Casts are not the right way to solve compiler errors. Check out The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^] so you get an understaning of string encodings.
|
|
|
|
|
BSTR[^]
typedef WCHAR OLECHAR;
typedef OLECHAR FAR * BSTR;
WCHAR[^]
#if !defined(_NATIVE_WCHAR_T_DEFINED)
typedef unsigned short WCHAR;
#else
typedef wchar_t WCHAR;
#endif
Maxwell Chen
|
|
|
|
|
Firs of all,
*THX* to all of you for your answers,
i tried it all ways but it still wont work, i could not find the mistake, i really don't know what i coud do !
These are my latest Codes:
VB:
<br />
Option Explicit<br />
<br />
Private Declare Function fnWin32DLL02 Lib "E:\WORKING\OMRON\GDT\EigeneDLL\Übergabe eines Strings aus C++ Dll\Win32DLL02.dll" () As String<br />
<br />
Private Sub Form_Load()<br />
<br />
Dim x As String<br />
<br />
x = Space$(3)<br />
x = fnWin32DLL02()<br />
MsgBox "X ist: " & x<br />
<br />
End Sub<br />
Cpp:
<br />
WIN32DLL02_API LPCSTR fnWin32DLL02(void)<br />
{<br />
LPCSTR s;<br />
s = "abc";<br />
return s;<br />
}<br />
Many thanx again
Croc
|
|
|
|
|
When using a Declare statement, Visual Basic converts strings (which it stores internally as Unicode UTF-16) to ANSI, using the default code page. There is no way to control which code page is used.
Your C++ DLL should therefore be ANSI throughout, i.e. using char* and derived types (e.g. LPSTR, LPCSTR).
On return from the function, ByRef parameters are converted back to Unicode as appropriate.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Hi everyone
Can you give give me a good tutorial about make device driver of course maybe you will be say that codeproject has articles about make it or if you use of google you can find a lot info about it but I want to start of first,what is device driver and then start to writing code?
Thanks
|
|
|
|
|
1) You have to install WDK (Windows Driver Kit) to compile the source code. Visual Studio (Visual C++) is not able to make device drivers (unless you install some third-party add-on to Visual C++).
2) Different type of device drivers require different callback functions. For example, a card reader driver has different callbacks from what a SCSI miniport driver has.
Maxwell Chen
|
|
|
|
|
Can you give me abour device driver what is it and I have VS2005 does it perfect for make it?
Thanks
|
|
|
|
|
messages wrote: abour device driver what is it
A device driver is to control a hardware device.
messages wrote: I have VS2005 does it perfect for make it?
No, VS2005 is useless to make a device driver. (But is good to view source code.)
You have to get a copy of WDK and install it. It will brought you some shortcuts to open DOS-box command-line environments for you to compile the source code.
Windows Driver Kit Homepage[^]
Maxwell Chen
|
|
|
|
|
|
Last year I can find some articles which is written for beginners. After upgrade those articles are missing. Who can tell me how to find them?
There is a will,there is a way!
|
|
|
|
|
What article or articles you need to see?
|
|
|
|
|
I downloaded a sample program in codeproject.com last year. I can’t find the article along with it.The demo project is named “TreePropSheetDemo”. Can you help me find it or tell me how to find it?
There is a will,there is a way!
|
|
|
|
|
(Sorry my system is having problem pasting URLs.)
Tree property sheet
http://www.codeproject.com/KB/tabs/treepropsheet.aspx
Tree property sheet Ex
http://www.codeproject.com/KB/tabs/treepropsheetex.aspx
Maxwell Chen
|
|
|
|