|
May be you could try forward declaration.
like
namespace Mammal
{
namespace Cat{ Class Siamese;}
}
then, the actual dog namespace
then, the actual cat namespace.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I am having a difficult time finding my problem in a dll that I am trying to build. This is really my first significant dll. I am trying to export a class from this dll - the dll itself has many classes that support this class, which are not exported, including some that use COM. Some of the supporting classes need to be initialized at the beginning. I am using MFC, but the class being exported is not based on MFC and all the functions in the class use parameters that do not require MFC - so I understand that I do not need to build an MFC extension dll.
I wrote a simple dialog application that included all the classes in the dll, and the dialog with a button that exercises the class that is being exported. Everything works fine. The supporting classes initialize properly, and all the functions in the class to be exported work as expected.
Then I created a project to make the dll with all the same classes. I built the dll and built a new dialog project to test the exported class in dll. The program 'hangs' during initialization that happens in the dll. Here is my problem. When I step through the code, when a function is completed the return statement does not go back to the calling function - it is as though the call stack is somehow corrupted, and there is no next place to step through for the code. How can I find out what is happening? I have never had this particular problem before.
I have another smaller dll that I developed the same way as this which works fine - the basic difference is that this one uses COM to do some ADO, and this dll also has some global variables.
Thanks in advance.
|
|
|
|
|
Does this mean your DLL statically links with MFC ?
Did you use the AFX_MANAGE_STATE macro ?
You might need to call this from each member function of your exported class.
Just because you don't directly export a function calling MFC does not mean that you don't still need to enter the correct state for each other function that is exported.
See "Managing the State Data of MFC Modules" in the MSDN.
|
|
|
|
|
Thanks for the response.
No, I am not statically linking with MFC.
Each of the function that is exported has the AFX_MANAGE_STATE macro in the first line.
I did read the article Managing the State Data of MFC Modules in MSDN, and think that I follow the recommendations.
The problem occurs in a function that is not exported. In fact, it is part of the initialization routine - which iscalled in the InitInstance in of the CWinApp derived class for the dll.
|
|
|
|
|
Does the EXE loading the DLL initialize COM ?
If so, does the COM initialization in the EXE occur prior to the initialization in the DLL ?
You might find that your DLL initialization will need to be deferred to an exported 'initialization' call, rather than in the InitInstance, which is basically the same as DLL_PROCESS_ATTACH. As a result of deferral, some class instances dependent upon COM, if they do 'interesting' operations in their constructors, might not be able to remain global, they might have to be created dynamically. The pointers to instances of the classes could be global, but not the instances of the classes themselves.
Basically, you might need to rework in this order, then:
EXE loads DLL (statically, I am presuming, since DLL is linked to EXE)
EXE initializes COM
EXE calls 'init' function exported from DLL
DLL 'init' function 'creates' global objects
...EXE does other work...
EXE calls shutdown function in DLL
DLL frees global objects
EXE uninitializes COM
Windows unloads DLL from EXE address space
EXE exits
You can also get into trouble with COM when creating instances and references to objects that MIGHT not be activated or deleted by the same thread in the EXE as those objects were created.
|
|
|
|
|
Thanks - I will try this - makes eminent sense. It is fairly straightforward to export an Init function that the .EXE's startup can call.
I had narrowed it to being a COM related issue as the inintialization works if I comment out the COM related code.
|
|
|
|
|
Thnaks,
Once I made sure that all initialization and COM calls came after the dll has been loaded - things worked out. I had to instantiate the global objects in an exported Init function subsequent to loading as you had suggested, and have a corresponding ShutDown function that cleaned up the gloabal objects before dll was unloaded. Having the cleanup code as part of unloading the dll frequently led to access violations.
|
|
|
|
|
In my application I've set the REALTIME_PRIORITY_CLASS.
It manages a worker thread that works at REAL_TIME_PRIORITY_LEVEL
(while the main thread has been set at IDLE_PRIORITY_LEVEL).
The goal'd be to let the worked thread to loop periodically
with its own multimedia timer without being stopped by the
user interface (in example when the user clicks the mouse).
My problem is that when the user stimulates the user interface
(mouse and windows) the worker thread stops for a while.
How can I let my theard loop without being affected by the
user actions ?
Is there a way to let the user interface to have really a very low
priority ?
Thanks a lot !
|
|
|
|
|
Hello,
You can try to set the prioity of your process to a higher level. Windows will give your process a bigger timeslice. Your process will give most of the time to your worker thread.
But be carefull with setting your process priority to realtime. If you do this, Windows will give almost all the time to your process and other applications could 'freeze' because there is no time left..
Hope this helps.
I also got the blogging virus..[^]
|
|
|
|
|
Thanks for your help but, as I've written in my first post,
I think to have already done what you say. I've used the following instructions in the InitInstance function of the App class:
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(THREAD_PRIORITY_IDLE);
Then I've used the next call in my worker thread:
SetThreadPriority(THREAD_PRIORITY_TIME_CRITICAL);
Is there something more to do ?
|
|
|
|
|
Hello,
There could be many reasons for your worker thread to stop for a while. A few of these reasons could be:
<list> Your processor is slow
Your GUI thread synchronizes access to some object with your worker thread using synchronization objects, that block your worker thread
The library that you are using is not very optimized
...
It should not be neccesary to set your process priority to realtime. If you don't let your worker thread run in it's own seperate process, windows ensures that it will always be interupted when the user stimulates the GUI...
I also got the blogging virus..[^]
|
|
|
|
|
Ok, so... as I was thinking the only way to really separate a thread by the user interface is to create it in a separate process created by the main application.
Thanks a lot for your advice !!
|
|
|
|
|
|
I'm stuck and would be really grateful if someone could help. I have written an application that builds an application to run on a Linux system!
The windows application that builds the Linux app has to create .cram files. the only way i know of doing this is using mkcramsf.exe but, with the size of the .cram file i am making, this takes ages (over 5 hours on a low spec PC!)
If i could find some source code on making a cram file i could embed that code into a function in one of my application classes and therefore speed the process up by a considerable ammount. It would appear (looking at examples available on the web) that this is not a common thing to attempt to acheive so i would be very grateful if anyone could help!
Thanks in advance to anyone who can.
steve333
|
|
|
|
|
I've tried to load the bitmap, which is already located in Access, to a picture loadbox on a FormView.
The process is that when I click a next button from a tool bar, the person's info. is changed.
When the program is run, the picture of the first person's image is loaded but not all people.
I wanna know DIB Funtion but all sources are based on API(Actually I am a real beginner.)
I've searched some books but the book explains just basic DIB process and just basic DB access.
Appreciate your advice that which Funtion prefer to.
Especially, what kind of process will be the best to get the bitmap image from the Access to the FormView.
Simple source will be more helpful.
Thanks and regards,
|
|
|
|
|
I'm trying to get the command line parameters of a running process. Does anyone know how to do this? I know I can set a windows hook with WH_SHELL, but I would like to be able to do it on the fly instead of having my application started before the processes I'm trying to view.
-- Rocky Dean Pulley
|
|
|
|
|
You could use the GetCommandLine API.
Put this API in a function and run the function remotely using CreateRemoteThread.
« Superman »
|
|
|
|
|
Thanks, that's what I'm about to try. I was hoping there was a way to do it without injecting anything but this will do I think.
Thanks,
-- Rocky
-- Rocky Dean Pulley
|
|
|
|
|
The fourth parameter to CreateRemoteThread() is the starting point of the new thread. How do you go about getting that starting point (i.e., function) into the other process?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
rocky_pulley wrote:
I'm trying to get the command line parameters of a running process.
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hello,
I am facing with a problem while trying to allocate very large memory by AWE APIs on Windows 2003 Advanced Server. I developed following code in order to allocate large memory portion, but I couldn't allocate it;
#include "stdafx.h"
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#define MEM_ALLOC 1024 * 1024 * 1024 * 4 // allocate physical memory
int _tmain(int argc, _TCHAR* argv[])
{
struct {
DWORD count;
LUID_AND_ATTRIBUTES privilege[1];
} info;
HANDLE token=0x0;
BOOL result=FALSE;
int iPageCount=0x0;
int PFNarraysize=0x0;
ULONG_PTR NumberOfPages=0x0;
ULONG_PTR* PFNarraylist=0x0;
SYSTEM_INFO sys_info;
PVOID lpMemoryWindow=0x0;
// get system page size
GetSystemInfo(&sys_info);
// calculate how many pages required
iPageCount = MEM_ALLOC / sys_info.dwPageSize;
// PFN requested size
PFNarraysize = iPageCount * sizeof(ULONG_PTR);
// allocate array for PFN array
PFNarraylist = (ULONG_PTR*)HeapAlloc(GetProcessHeap(), 0, PFNarraysize);
// ------------------------------------------------------------- //
// check user privileges in order to lock memory on the system
result = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token);
// set privilege attributes
info.privilege[0].Attributes = SE_PRIVILEGE_ENABLED;
// lookup user privileges
result = LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &(info.privilege[0].Luid));
// info count
info.count=0x1;
// retrieve user privilege
result = AdjustTokenPrivileges(token, FALSE, (PTOKEN_PRIVILEGES)&info, 0, NULL, NULL);
// close token handle
CloseHandle(token);
// ------------------------------------------------------------- //
// create memory window
lpMemoryWindow=VirtualAlloc(NULL, MEM_ALLOC, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE);
NumberOfPages = iPageCount;
// allocate physical memory - I
result = AllocateUserPhysicalPages(GetCurrentProcess(), &NumberOfPages, PFNarraylist);
// map user physical page to the window - I
result = MapUserPhysicalPages(lpMemoryWindow, iPageCount, PFNarraylist);
// use memory
lstrcpy((LPSTR)lpMemoryWindow, TEXT("OGED"));
}
In the example that I wrote above can allocate 2 gb or less memory but not more and I am sure that I have 16 Gb physical memory.
How can I allocate and use more than 4 Gb memory? Can anybody give an example about AWE?
PS: I am aware about MSDN AWE and MSDJ - 99 examples, but they are not a solution for my case.
Regards,
Orkun GEDiK
SAP R/3 Software & System Support Specialist
ASTRON
|
|
|
|
|
You do not say it or not, but are you booting with the /PAE switch? You need it to enable applications to address at and above 4GB. Normally, you can only address 2GB unless you booted with the /3GB switch.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hello,
Sorry, I forgot to say that, "I am using /PAE switch already".
Regards,
Orkun GEDiK
SAP R/3 Software & System Support Specialist
ASTRON
|
|
|
|
|
Codeguru,
I have a property sheet, which contains a nmber of property pages. One of the pages contains a CTreeCtrl.
The tree control is used to display a list of items with tick boxes. The list of items never changes, however the ticks next to then respond to changes in the document structure.
I use OnInitDialog to create the list of elements using InsertItem and also log the handles for later use.
I then use OnSetActive to record each time the user clicks the page and update the tick boxes using SetCheck and the recorded handles from OnInitDialog.
My problem:...
The property page has to be shown twice, first the items appear and second the tick boxes are correct. Thereafter everything works fine.
I'm presuming this is because the inserted items have not been activated until after the page is made visible? Therefore SetCheck doesn't do anything on the first pass. But I've tried to resolve this with a call the the property sheet to call another page, using SetActivePage(*), then reactivating the current one. However, this doesn't work. Also tried various update calls inbetween OnInitDialog and OnSetActive, but to no avail.
Any ideas what I'm doing wrong? The help would be very much appreciated
James
|
|
|
|
|
I remembered dealing with a quirky problem involving CTreeCtrl checkboxes. I checked some code in an old project, and found this:
<br />
<br />
m_treeCtrl.ModifyStyle(TVS_CHECKBOXES, 0);<br />
m_treeCtrl.ModifyStyle(0, TVS_CHECKBOXES);<br />
The fix came via the one of the newsgroups. I don't know if it will help your problem, but it's worth a shot.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|