|
I can't change the way the ported code defines it's memory. It would be a huge change. Not only am I creating a section for the structures in the example, I'm creating sections for all of the BSS section and sections for other variables that the original devlopers have sprinkled throughout the code. This all happens at compile time with the embedded target linker. The "placement new" looks to me like it's dynamically allocating the memory. I would have to change the declaration for every variable in the ported code and that would be well in the hundreds.
If this was a new project built for Windows then I could use "placement new".
Does that make sense?
Brad Grupczynski
|
|
|
|
|
This solves your problem.
/SECTION[^]
syntax
/SECTION:name,[[!]{DEKPRSW}][,ALIGN=#]
The ALIGN=# lets you specify an alignment value for a particular section. See /ALIGN for more information.
Maxwell Chen
|
|
|
|
|
I tried this. And I tried just using /ALIGN:1. That didn't work either.
I try these link options:
/SUBSYSTEM:NATIVE /DRIVER:WDM /SECTION:MY,,ALIGN=0x0001
(Because I use /SECTION, I am required to use /DRIVER. And Since I use /DRIVER:WDM, I am required to use /SUBSYSTEM.)
I get:
fatal error LNK1137: invalid argument '??????' specified with /SECTION.
'??????' comes up as few boxes. Not sure why this isn't more graceful.
But it does work with ALIGN >= 4k which is the default section size.
/SUBSYSTEM:NATIVE /DRIVER:WDM /SECTION:MY,,ALIGN=0x1000 works just fine.
Brad Grupczynski
|
|
|
|
|
bgrupczy wrote: I tried this. And I tried just using /ALIGN:1. That didn't work either.
I try these link options:
/SUBSYSTEM:NATIVE /DRIVER:WDM /SECTION:MY,,ALIGN=0x0001
(Because I use /SECTION, I am required to use /DRIVER. And Since I use /DRIVER:WDM, I am required to use /SUBSYSTEM.)
I get:
fatal error LNK1137: invalid argument '??????' specified with /SECTION.
'??????' comes up as few boxes. Not sure why this isn't more graceful.
But it does work with ALIGN >= 4k which is the default section size.
/SUBSYSTEM:NATIVE /DRIVER:WDM /SECTION:MY,,ALIGN=0x1000 works just fine.
See this: /ALIGN[^].
The /ALIGN option specifies the alignment of each section within the linear address space of the program. The number argument is in bytes and must be a power of two. The default is 4K (4096). The linker issues a warning if the alignment produces an invalid image.
Maxwell Chen
|
|
|
|
|
If I try with /ALIGN:2
I get:
fatal error LNK1164: section 0x1 alignment (16) greater than /ALIGN value
I think that's why I get:
fatal error LNK1137: invalid argument '??????' specified with /SECTION.
When when I used:
/SUBSYSTEM:NATIVE /DRIVER:WDM /SECTION:MY,,ALIGN=0x0001
And it didn't work for any power of 2 until I got to 4K (0x1000).
Brad Grupczynski
|
|
|
|
|
As in my previous reply some hours earlier, the below setting is accepted by VC++2005. The compilation is fine without any errors. But it looks not working. There is still a gap between struct B69 and struct B37.
/SECTION:MY,RW,ALIGN=2
Maxwell Chen
|
|
|
|
|
I just re-read your response. The ee_block_bl_type structure is packed to byte alignment. And there aren't any other sections in between.
Brad Grupczynski
|
|
|
|
|
I figured it would be a stretch to expect padding to account for the increase from 69 to 344 bytes.
Without looking at the code as a whole i don't expect you will be able to get much more help here.
Aside from that, the /SECTION and /ALIGN options, as mentioned elsewhere, aren't of any use as the alignment refers to the section as a whole, not the alignment/packing within.
Again, i don't believe there is a way to specify the alignment/packing within a section.
I tested the following sample:
#pragma pack(push, 1)
typedef struct {
char a[73];
double b;
char c[73];
} sa;
#pragma pack(pop)
typedef struct {
char b[100];
} sb;
#pragma bss_seg(push, "MY$AA")
sa a;
#pragma bss_seg(pop)
#pragma bss_seg(push, "MY$AB")
sb b;
#pragma bss_seg(pop)
I compiled for both x86 and x64.
- Both resulted in 8 byte alignment within the section (not 4).
- Both honoured the #pragma pack() statements.
Without the #pragma pack(), they packed using normal packing rules (e.g. double a.b aligned on 8 byte addr, if changed to long a.b, aligned on 4 byte addr).
- The results for the above, with packing:
&a.a = 0x...00
&a.b = 0x...49 73
&a.c = 0x...51 81 = 73 + 8
&b = 0x...a0 160 = 154 (81+73) round up to next 8
So, from the above it seems you should have &b = 0x...48 for you code.
The fact that you don't would cause me to look elsewhere.
- Are you sure ee_block_bl_type is 69 bytes.
- Are any of its members other structures that may not be packed.
- Do any of its members have macro defined types/sizes.
- What are the results from dummpbin for the app as a whole and the "MY" section. In particular the raw dump of "MY" 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
|
|
|
|
|
How about the below sample?!
Compile in Release Mode with VC++ 2005.
Additional option=
/SECTION:MY,RW,ALIGN=2
#pragma pack(1)
struct B69
{
int a;
int b;
short c;
char d[59];
};
struct B37
{
char a[37];
};
#pragma pack()
#pragma bss_seg(push, "MY$AA")
B69 b69;
#pragma bss_seg(pop)
#pragma bss_seg(push, "MY$AB")
B37 b37;
#pragma bss_seg(pop)
void main()
{
printf("sizeof(B69) = %d \n", sizeof(B69));
printf("b69 = %p, \n"
"b69.a = %p, b69.b = &p, b69.c = %p, b69.d[0] = %p \n"
"b69.d[58] = %p, b37 = %p \n",
&b69,
&b69.a, &b69.b, &b69.c, &b69.d[0],
&b69.d[58], &b37 );
}
Result:
sizeof(B69) = 69
b69 = 00402000,
b69.a = 00402000, b69.b = 00402004, b69.c = 00402008, b69.d[0] = 0040200A,
b69.d[58] = 00402044, b37 = 00402048
Maxwell Chen
|
|
|
|
|
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]
|
|
|
|
|