|
Hi all,
I have a set of EXEs and an ActiveX control (ATL DLL) that perform some processing when invoked (the EXEs are invoked as usual from the command line and the ActiveX is invoked through scripting on a web page). Neither of these have a UI.
I now need to show a simple dialog box (a few fields for the user to fill) under some conditions determined by code in the EXEs or ActiveX. I don't want to have to duplicate UI code, so the discussion I've been having with The Powers That Be are leading towards putting the dialog box and its associated code in a DLL and call it as needed from the EXEs and the ActiveX.
The EXEs were written with the raw Win32 API (no MFC, no library at all in fact, no message pump either as they don't have a UI), and the ActiveX uses ATL. Both would now need to call a single function exported from my new DLL to show a UI as needed.
What is the simplest way to accomplish this, considering these requirements:
a) My DLL must be as small as possible
b) Can't duplicate UI code, must produce a single DLL
c) Neither EXEs or ActiveX DLL are allowed to become dependent on MFC or any large UI library. In fact I'm not allowed to introduce any new dependencies at all apart from this new DLL itself.
Normally if I had to display a simple form with those restrictions I'd write a simple Win32 EXE, and stick with the raw Win32 API and write the UI code with nothing else. A dialog box and a message pump--simple enough.
Can I, however, have a DLL exporting one function which, when called, displays this dialog box...and can still be called both from the EXEs and the ATL-based ActiveX? This is where my knowledge on the internals of ATL is limited: will a Win32 message pump residing in my DLL cause any problem?
Actually, the more I think about it, the more I believe my question doesn't necessarily rely with ATL, but rather, can a raw Win32 API application and an ATL DLL both call a DLL that has a self-contained dialog box and its own message pump?
Argh, I don't don't even know if I'm making any sense anymore...
I hate this, this should be simple but it's just not the type of thing I'm used to writing...
|
|
|
|
|
You can call ::DialogBox inside of your DLL function that has been exported, and that is all that you would need. You could develop a more elaborate UI if you desired using the raw Win32 API, or even WTL, but I think that would be overkill in this case.
DialogBox creates a message pump on the stack for you (that is how it becomes a modal window), and when you close the dialog box the message pump goes away with the dialog box.
You may want to add in some sort of synchronization in your DLL to only allow one of these dialog boxes to appear at a time, but I guess that all depends on how you want your system to work.
Lastly, this does not depend on any frame work, so you will be in the clear.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
?!? Gee Paul, you're absolutely right.
I think I've been looking at this problem for a little too long in a single sitting... I've re-read the message I posted yesterday and it's not exactly the most, uh, let's say "coherent" message I've ever posted.
Thanks for the quick reply (and sending me off in the right direction). I sense a sudden surge of inspiration...
|
|
|
|
|
Daniel Desormeaux wrote:
What is the simplest way to accomplish this, considering these requirements:
a) My DLL must be as small as possible
Then you simply have no choice: You must create your dialog on-the-fly to no have a RESOURCE (.rsrc) section in the DLL. I have done this myself for a simple text-input dialog usable from anywhere (as .lib or in a DLL or...) without messing up with resource ID's and such. Perhaps something similar could be of use for you?
Can I, however, have a DLL exporting one function which, when called, displays this dialog box...and can still be called both from the EXEs and the ATL-based ActiveX?
Yes. To be 100% sure (well, assuming resources are available) that it always works you'd however need to do something like what I've outlined.
I hate this, this should be simple...
I agree. However, it is Micros~1 created code we are dealing with...
|
|
|
|
|
> create your dialog on-the-fly to no have a RESOURCE (.rsrc) section
Ok, overkill. I need it to be as small as possible, but not that small. I'm still allowed to compile an .RC file.
Using Paul's excellent post (and much more to-the-point than mine) as a starting point, I managed to put this together without duplicating code and without any separate DLL. I do have to include the .RC in the EXEs and ActiveX projects, but I'm happy with this solution.
|
|
|
|
|
Hi
I'm programming a tool that collects game server IPs and logs them into a file. The logging is fine, however there are a lot servers with the same IP, that's why I want servers already logged not to be logged into the file again.
What is the best approach? Should I use an array, a linked list or something else where I should store all IPs in form of a string? And how can I search for strings inside an array/linked list etc.? Furthermore the technique should be very fast.
/edit: I should mention that I can't use MFC, only plain Win32 API
If someone could give me a hint or a link I would be very grateful
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Use an STL set - it doesn't allow duplicates, and has log(n) time for searching.
Dave
|
|
|
|
|
|
Thanks!
I will give it a try
modified 12-Sep-18 21:01pm.
|
|
|
|
|
My function looks like this:
void ReplaceString(char *szSourceString, const char *szToReplace, const char *szReplaceWith)
{
char *szReplacePos = strstr(szSourceString, szToReplace);
char *szFirstPart = new char[strlen(szSourceString)];
while (szReplacePos != NULL)
{
memset(szFirstPart, 0, strlen(szSourceString));
strncpy(szFirstPart, szSourceString, szReplacePos-szSourceString);
strcat(szFirstPart, szReplaceWith);
strcat(szFirstPart, &szReplacePos[strlen(szToReplace)]);
strcpy(szSourceString, szFirstPart);
szReplacePos = strstr(szSourceString, szToReplace);
}
delete[] szFirstPart;
}
The szFirstPart pointer never changes but i still get a user breakpoint message. I have't free'd it before in the while loop so i don't understand it, any ideas?
THanks
|
|
|
|
|
|
Anonymous wrote:
char *szFirstPart = new char[strlen(szSourceString)];
char *szFirstPart = new char[strlen(szSourceString)+1]; // + 1 for the EOL char
Then take that char into account everywhere, for instance :
memset(szFirstPart, 0, strlen(szSourceString));
becomes
memset(szFirstPart, 0, strlen(szSourceString)+1);
How low can you go ? (MS rant)
|
|
|
|
|
I all,
I'm attempting to write an application using the doc/view arch. and I'm not sure how to do the following:
I want to have multiple views of a single document (read, different views using different dialogs and the like). A similar way to look at it would be the windows explorer. 2 very different views of the same data. That is in essence what I want to do, but each view has its own dialog box and set of functions associated with it. They are implemented as seperate dlls since they are used in many other applications.
Can I do this by setting up the splitters correctly?
What do I have to do to display these other dialog boxes within that particular view?
Any suggestions are greatly appreciated, even if it is another way of approaching the manner. I am using toolbars and rebars extensively and thought the doc/view approach would be the way to go.
Thank you in advance. This could be a complicated matter (it is to me!)
Dan
|
|
|
|
|
Yes, it is possible to implement multiple views of a single document and it can be done with a splitter frame.
The simplest solution for multiple concurrent dialog boxes is modeless style over modal style. Otherwise, consider a propertysheet.
Kuphryn
|
|
|
|
|
Hi,
I can override WM_ERASEBKGND and fill the control but it is valid only when the control has not the focus. If it gains focus, the text is drawn with a background system color (COLOR_WINDOW), WM_CTLCOLOR is not called.
Any idea ?
Nicolas
|
|
|
|
|
|
I dont know where to post this. My MFC app has a HElp Menu item> i want to launch the tripane help window from this button. My HTMLHELP workshop book tells me how to make a help project so I am assuming that I have the .chm file. Now I need to know how to launch this using the HTMLHelp API.....
|
|
|
|
|
You can use the ShellExecute function:
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
As operation you specify "open", as file your .chm file.
-Dominik
|
|
|
|
|
|
try using the remove(), replace(), insert() members of CString
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
How do i use them on a char array?
|
|
|
|
|
You can't directly (not that I'm aware of anyways. However, one way would be to declare a CString and set it to your char array (CString str = charArray;) and them use the CString members mentioned earlier, are you could use the <string.h> functions such as strcat(), strcpy(), etc... Personally I prefer working with the CString as that wrapper class seems more flexible to me (or maybe its just cause I'm used to it). Either way would work fine and of course, you could also just use pointers and remove/replace in your char array as you like.
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
hello!
i have a splash screen (greeting screen) in my mfc-programm. how can i change the time?(i would like to see the picture longer.)
thanks
MFC
|
|
|
|
|
search in your code for SetTimer
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
|