|
What about it ?
&b37 = 0x...48 = 72, which is a multiple of 8.
The ALIGN=2 did nothing to effect the layout within the section.
...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
|
|
|
|
|
cmk wrote: - What are the results from dummpbin for the app as a whole and the "MY" section. In particular the raw dump of "MY" section.
I haven't used dumpbin before but am willing to try anything. I will look into what dumpbin is and how to use it. I'm assuming that it'll show me the memory layout and I can see if there's something getting stuck in between my sections.
cmk wrote: - Are you sure ee_block_bl_type is 69 bytes.
Yes. I looked at it with sizeof(). It's 69.
cmk wrote: - Are any of its members other structures that may not be packed.
Everything is packed tight. The fact that sizeof(ee_block_bl_type) is 69 proves this, right?
cmk wrote: - Do any of its members have macro defined types/sizes.
The structure has substructures and fundamental types. But they all look good.
I'll be back with my dumpbin results.
Brad Grupczynski
|
|
|
|
|
This is what I get from dumpbin for the app (compiled as DLL actually) as a whole:
SECTION HEADER #3
MY name
8E91 virtual size
120000 virtual address (10120000 to 10128E90)
0 size of raw data
0 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0000080 flags
Uninitialized Data
Read Write
Summary
9000 MY
I don't see any allocation to raw data.
I also dumpbin'd the .obj file:
Summary
1 .bss
4FB8 .debug$S
44 .debug$T
D1 .drectve
4 .rtc$IMZ
4 .rtc$TMZ
1704 .text
F9E MY$BSS_B
45 MY$EE_B_A
4B MY$EE_B_B
CF MY$EE_B_C
D2 MY$EE_B_D
29 MY$EE_B_E
6A MY$EE_B_F
6A MY$EE_B_G
3B MY$EE_B_H
1E MY$EE_B_I
26E MY$EE_B_J
Sure enough, the sections are the right size. It's just how their assembled in memory.
Does this give you a clue?
(This next paragraph might become a new thread)
You can see that I'm also trying to get all of the other variables places in my BSS_B section. But I'm missing some of the variables that are declared static throughout the code. There is one byte in this .obj file which is getting placed in .bss. I can't get them in my BSS_B section. Any help? Or is there a way for me to get ahold of a pointer to the beginning and end of the .bss section?
Brad Grupczynski
|
|
|
|
|
bgrupczy wrote: But I'm missing some of the variables that are declared static throughout the code.
Whoops, unitialized data doesn't have raw data (no initial values to store).
bgrupczy wrote: I'm missing some of the variables that are declared static throughout the code.
Statics are initialized data (default init to 0), they are stored in .data by default. You can use #pragma data_seg() instead of #pragma bss_seg() to control their section. I'm fairly sure you can't merge with your bss seg (ie. can't use same name "MY$...").
bgrupczy wrote: There is one byte in this .obj file which is getting placed in .bss. I can't get them in my BSS_B section.
Do you know which byte ?
The dumpbin of the .obj actually makes me think there might be a way to use /SECTION ALIGN to get what you want. I had thought that the .obj would contain the merged section "MY" and it's attributes/alignment.
After looking at your dump, and testing myself, is seems it stores each pre-merge sections, each with it's own attributes/alignment. If you do dumpbin /section:MY$EE_B_A your.obj you will see the alignment (mine is 8).
I tried the following without success:
#pragma comment(linker, "/SECTION:MY,R,W,ALIGN=1")
- compiles/links without warning/error, but doesn't effect pre-merged section alignment value.
#pragma comment(linker, "/SECTION:MY,R,W,ALIGN=1")
- link fails with invalid section name.
...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
|
|
|
|
|
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
|
|
|
|