Prev: Volume Shadow Copy Service error: Unexpected error calling routine CoCreateInstance. hr = 0x800401f0
Next: 2GB virtual memory limit
From: David F. on 26 Feb 2010 21:28 I have a class constructor that needs to use GetNativeSystemInfo but it's not available at that point if the object is a variable (not allocated with new). However, GetSystemInfo is. I've tried the following both within the constructor and global yet the only one consistantly available is GetSystemInfo. However, if you later either dynamic allocate a new object or make a call to one of the member functions the fnGetNativeSystemInfo is then non-NULL. Why would that be? typedef void (WINAPI *LPFN_GetSystemInfo) (LPSYSTEM_INFO lpSystemInfo); LPFN_GetSystemInfo fnGetSystemInfo=(LPFN_GetSystemInfo) GetProcAddress(GetModuleHandle("kernel32"), "GetSystemInfo"); LPFN_GetSystemInfo fnGetNativeSystemInfo=(LPFN_GetSystemInfo) GetProcAddress(GetModuleHandle("kernel32"), "GetNativeSystemInfo");
From: Tim Roberts on 27 Feb 2010 01:45 "David F." <df2705(a)community.nospam> wrote: > >I have a class constructor that needs to use GetNativeSystemInfo but it's >not available at that point if the object is a variable (not allocated with >new). However, GetSystemInfo is. So, it doesn't work at process initialization time, but does work after loading? Is this in an EXE or a DLL? >I've tried the following both within the >constructor and global yet the only one consistantly available is >GetSystemInfo. However, if you later either dynamic allocate a new object >or make a call to one of the member functions the fnGetNativeSystemInfo is >then non-NULL. Why are you fetching these dynamically, instead of linking statically? -- Tim Roberts, timr(a)probo.com Providenza & Boekelheide, Inc.
From: Stefan Kuhr on 27 Feb 2010 02:33 Hi David, On 2/27/2010 3:28 AM, David F. wrote: > I have a class constructor that needs to use GetNativeSystemInfo but > it's not available at that point if the object is a variable (not > allocated with new). However, GetSystemInfo is. I've tried the following > both within the constructor and global yet the only one consistantly > available is GetSystemInfo. However, if you later either dynamic > allocate a new object or make a call to one of the member functions the > fnGetNativeSystemInfo is then non-NULL. > > Why would that be? > > typedef void (WINAPI *LPFN_GetSystemInfo) (LPSYSTEM_INFO lpSystemInfo); > LPFN_GetSystemInfo fnGetSystemInfo=(LPFN_GetSystemInfo) > GetProcAddress(GetModuleHandle("kernel32"), "GetSystemInfo"); > LPFN_GetSystemInfo fnGetNativeSystemInfo=(LPFN_GetSystemInfo) > GetProcAddress(GetModuleHandle("kernel32"), "GetNativeSystemInfo"); > Are you calling this from a constructor of a global variable in a DLL? -- S
From: David F. on 27 Feb 2010 13:20 It would be like this: -- class header -- class MyClass { protected: bool m_x64; public: MyClass(void); virtual ~MyClass(void); } -- class implementation -- typedef void (WINAPI *LPFN_GetSystemInfo) (LPSYSTEM_INFO lpSystemInfo); LPFN_GetSystemInfo fnGetSystemInfo=(LPFN_GetSystemInfo) GetProcAddress(GetModuleHandle("kernel32"), "GetSystemInfo"); LPFN_GetSystemInfo fnGetNativeSystemInfo=(LPFN_GetSystemInfo) GetProcAddress(GetModuleHandle("kernel32"), "GetNativeSystemInfo"); MyClass::MyClass() { m_x64=false; if (fnGetNativeSystemInfo) { .... set m_x64=true if on AMD64 ... } else if (fnGetSystemInfo) { .... set m_x64=true if on AMD64 ... // does no good under WOW64 } // test - this also fails when fnGetNativeSystemInfo is null (which is weird to me since I could see global initialization race condition but..) LPFN_GetSystemInfo fn=(LPFN_GetSystemInfo) GetProcAddress(GetModuleHandle("kernel32"), "GetNativeSystemInfo"); }; -- user app -- MyClass MyClassObj; // this object fnGetNativeSystemInfo is NULL during construction but fnGetSystemInfo is not. int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPTSTR lpcmdline, int nshowcmd) { ... MyClassObj.SomFunc() // fnGetNativeSystemInfo would be available at this point. MyClass *myclassobj=new MyClass(); // this object fnGetNativeSystemInfo is available during construction (as is fnGetSystemInfo). }; However it did change once when I link to the .OBJ instead of a larger .LIB then that class was working in both cases, but when going back to linking to LIB the difference showed up. It's an x32 multi-byte app static linked to LIB that includes the class. run on Win7 x64 but needs to run on WinNT and Win9x as well. "Tim Roberts" <timr(a)probo.com> wrote in message news:r3fho51tvpl3u579jl8qughclj3f81b19t(a)4ax.com... > "David F." <df2705(a)community.nospam> wrote: >> >>I have a class constructor that needs to use GetNativeSystemInfo but it's >>not available at that point if the object is a variable (not allocated >>with >>new). However, GetSystemInfo is. > > So, it doesn't work at process initialization time, but does work after > loading? Is this in an EXE or a DLL? > >>I've tried the following both within the >>constructor and global yet the only one consistantly available is >>GetSystemInfo. However, if you later either dynamic allocate a new object >>or make a call to one of the member functions the fnGetNativeSystemInfo is >>then non-NULL. > > Why are you fetching these dynamically, instead of linking statically? > -- > Tim Roberts, timr(a)probo.com > Providenza & Boekelheide, Inc.
From: Tim Roberts on 28 Feb 2010 20:10
"David F." <df2705(a)community.nospam> wrote: > >It would be like this: > >-- class header -- >class MyClass >{ > protected: > bool m_x64; > public: > MyClass(void); > virtual ~MyClass(void); >} > >-- class implementation -- > >typedef void (WINAPI *LPFN_GetSystemInfo) (LPSYSTEM_INFO lpSystemInfo); >LPFN_GetSystemInfo fnGetSystemInfo=(LPFN_GetSystemInfo) >GetProcAddress(GetModuleHandle("kernel32"), "GetSystemInfo"); >LPFN_GetSystemInfo fnGetNativeSystemInfo=(LPFN_GetSystemInfo) >GetProcAddress(GetModuleHandle("kernel32"), "GetNativeSystemInfo"); Where is this code, exactly? Remember that your global variable initialization will happen when the binary that contains it is loaded, before any of the code in the binary. If you have that code in a "main" somewhere, then the variables will not be initialized when your global MyClass object is constructed. -- Tim Roberts, timr(a)probo.com Providenza & Boekelheide, Inc. |