Re: Unaligned members in a class

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hmmm. I can't get it to fail. I'm using your a.h, a.cpp, b.h, and b.cpp
code unchanged and here's my main code:

#include <windows.h>
#include "a.h"

A a;
A a1;
A a2;

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd
)
{
a1.doSomthing();
a2.doSomthing();
a.doSomthing();

return 0;
}

This works just fine on my PXA255-based device running Windows CE.NET 4.2.
Are you sure that you've compiled the library to target the right device and
not Standard SDK or something weird like that?

Are you using eVC++ 4.0 SP4?

Paul T.

"JR Lyon" <jrlyon@xxxxxxxxxxx> wrote in message
news:eLERvsqoFHA.568@xxxxxxxxxxxxxxxxxxxxxxx
>I guess you can't do attachments here :( So here is the code for the A and
>B
> classes:
>
> A.cpp**********************************
> #include "A.h"
>
> A::A()
> {
> i = 0;
> iPtr = new int;
> }
>
> A::~A()
> {
> delete iPtr;
> }
>
> void A::doSomthing()
> {
> i = 5;
> }
>
> A.h**************************************
> #include "B.h"
>
> class A
> {
> public:
>
> A();
> ~A();
> void doSomthing();
>
> private:
> B b;
> int i;
> int* iPtr;
> };
>
> B.cpp*************************************
> #include "B.h"
>
> B::B()
> {
> i = 4;
> ip = new int;
> }
>
> B::~B()
> {
> delete ip;
> }
>
> void B::doSomthing()
> {
> i = 5;
> }
>
> B.h*****************************************
> class B
> {
> public:
>
> B();
> ~B();
> void doSomthing();
>
> private:
>
> long i;
> int* ip;
> };
>
> You make these classes in a library and then link to them in the Hello
> World
> app. It has to be through a library as link normally works fine
>
> JR
> "JR Lyon" <jrlyon@xxxxxxxxxxx> wrote in message
> news:OzAS%23NqoFHA.3312@xxxxxxxxxxxxxxxxxxxxxxx
>> OK I was finally able to reproduce it on a fairly small level. Ive
> included
>> the prject which builds a lib for the PPC. When I built this lib I then
>> created a new hello world app for PPC and at the top where it said
> //Globals
>> I added these lines
>>
>> // Global Variables:
>> #include "A.h"
>>
>> A a;
>> A a2;
>> A a3;
>>
>> It works fine when I only instantiate one but two or more it starts to
> fail
>> giving access violations this time. The 'A' class, when it is
>> instantiated
>> instantiates the 'B' class. With out this extra instantiation it works
> fine
>> as well.
>> Again I can't thank you enough for helping me with this isssue
>>
>> JR Lyon
>>
>> "JR Lyon" <jrlyon@xxxxxxxxxxx> wrote in message
>> news:um3h0LeoFHA.3608@xxxxxxxxxxxxxxxxxxxxxxx
>> > I have a class which has members that are private:
>> >
>> > class A
>> > {
>> > private:
>> > int B;
>> > };
>> >
>> > However I got the infamous "Datatype misalignment" error when I put
>> > this
>> > class in a static library (.lib file), when it's not in the lib it runs
>> > fine. So I did some snooping around and the address of this class is
>> > mod
> 4
>> > so thats aligned but none of the members are aligned. Their addresses
> are
>> > all off by 2 bytes. I also tried this from suggestions of the net:
>> >
>> > class A
>> > {
>> > private:
>> > __unaligned int B;
>> > };
>> >
>> > No avail :( Again I have no problem when I link the class straight into
>> the
>> > exe (ie include it in the project) but when I make it a library and
>> > link
>> it
>> > in that way it fails. Thanks in advance for any help
>> >
>> > JR
>> >
>> >
>>
>>
>
>


.



Relevant Pages

  • Re: CreateProcess() its extermely slow
    ... CMD.EXE's START command. ... ATOM MyRegisterClass(HINSTANCE hInstance); ... BOOL InitInstance(HINSTANCE, int); ... LPARAM lParam) ...
    (microsoft.public.vc.language)
  • Re: Waitable Timer
    ... int APIENTRY _tWinMain(HINSTANCE hInstance, ... LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Load any Bmp or Jpeg file
    ... ATOM MyRegisterClass(HINSTANCE hInstance); ... BOOL InitInstance(HINSTANCE, int); ... // PURPOSE: Registers the window class. ... HDC hdc,MemDCExercising; ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Flickering problem (new to Windows GDI programming)
    ... of our player ... ATOM MyRegisterClass(HINSTANCE hInstance); ... BOOL InitInstance(HINSTANCE, int); ... movePlayer = DOWN; ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Flickering problem (new to Windows GDI programming)
    ... of our player ... ATOM MyRegisterClass(HINSTANCE hInstance); ... BOOL InitInstance(HINSTANCE, int); ... movePlayer = DOWN; ...
    (microsoft.public.win32.programmer.gdi)