|
cmk wrote: Do you know which byte ?
Yes, it's one of the variables declared static within a function. But I'm going to try to use the data_seg() to see if I can capture it.
The reason I need to get all of the variables in my named sections is for the code to do a memset wipe of certain sections. Just like in an embedded system. I have other "start" and "end" variables that I put alphabetically before and after the sections so I have a handle around them. I wish there was a way to get the pointer to the beginning and end of named sections. Or to .bss or .data for that matter.
Looks like both of your examples are identical...(?)
And I'll take a look at that exact section with dumpbin to see what I get.
Brad Grupczynski
|
|
|
|
|
Whoops,
#pragma comment(linker, "/SECTION:MY,R,W,ALIGN=1")
- link fails with invalid section name.
change /SECTION:MY to /SECTION:MY$AA
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Hmmm, I don't know what was wrong with my system. Today, those linker options are working with no compilation errors! And the memory is packed down to 8 byte alignment. This is MUCH better. The ported target code can handle this small fragmentation.
If I only use:
/SECTION:MY,R,W,ALIGN=1
Then I don't get the 8 byte packing. The two MY sections are always separated by 344 bytes.
But if I use this directive:
/SUBSYSTEM:NATIVE /DRIVER:WDM /SECTION:MY,R,W,ALIGN=1
Then I get the 8 byte alignment. But then the DLL won't execute in my test tool, MxVDev. That's my next hurtle.
Thanks for the help. I don't think there is a way to get them to pack any tighter.
Brad Grupczynski
|
|
|
|
|
Anyone know how to do it ?
|
|
|
|
|
You mean Shift_JIS? And also, do you really mean ASCII or Windows CP1252 (aka ANSI)?
In any case, you can convert from Shift_JIS to Unicode (UTF-16) first with MultiByteToWide (please check if I spelled it correctly) and then from Unicode to CP1252 with WideToMultiByte .
|
|
|
|
|
Nemanja Trifunovic wrote: You mean Shift_JIS?
the docs i have say the text is encoded in "JIS X0208-1990 x i" .
Nemanja Trifunovic wrote: do you really mean ASCII or Windows CP1252 (aka ANSI)?
ANSI, i guess: plain-old text.
|
|
|
|
|
Chris Losinger wrote: the docs i have say the text is encoded in "JIS X0208-1990 x i" .
Yep, that's it[^]. I think your best bet is to first convert it to Unicode by calling MultiByteToWideChar[^] (the shift_jis code page is 932[^] and then the resulting wide string to ANSI by using WideCharToMultiByte[^] with the codepage 1252 to get it as ANSI. IIRC, any "non-western" Japanese characters would map to question marks, but you can control it with the lpDefaultChar parameter.
Chris Losinger wrote: plain-old text.
No such thing in the global economy
|
|
|
|
|
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
|
|
|
|