|
Hello ! Michael P Butler
tanks.
|
|
|
|
|
The import library produced by MS Visual C++ is in COFF format (Mangled Names), and Delphi and Borland C++ expects things in OMF format.
See the July 1996 "Under the Hood" article of Microsoft Systems Journal. It talks about different dll formats and ways to get round this.
|
|
|
|
|
Hello ! Rashid Thadha ....
Tanks!;)
|
|
|
|
|
I have a list that is always kept sorted. ie, when an item is added, it gets added at a position that will keep the list sorted. I am using binary search now to identify the location to insert the item.
Is there a better algorithm than this?
Thanks in advance for any suggestions.
-Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
A binary tree with linked lists to allow for equal nodes?
> Andrew.
|
|
|
|
|
I am now using a CPtrList, that contains pointers to structures. I have an InsertSorted(DATA_STRUCT* pStruct), that inserts based on binary sort. Will the binary tree model be able to be implemented inside this InsertSorted?
In any case, I will have to do some research on the binary tree model and make a sample to compare the performance advantage.
Thanks for the reply.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
If you were using STL, the set or map would do this for you automatically, you'd only need to add an element for it to be sorted.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I will try that out. The functionality is encapsulated in a class. I will re-write the class using STL and check for performance improvement.
Thanks
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I was reading through the map and set docs in MSDN. Rightnow, I have a compare function, that compares based on different items in the structure depending on user settings. Is there a place, where I can define a custom comparison function in these classes? I did not find any.
Any help is very much appreciated.
Thanks
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Yes, you can provide a function of your choice that return a bool. It's the last argument of the algorithm, and is optional.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
You can either overload the "<" operator for your structure, or use a function object as the sorting criterion for a map or set. The STL documentation in MSDN is really bad, you need some other information source.
|
|
|
|
|
I think you'll have better use with CTypedPtrList instead of CPtrList
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
I may be lazy, but why not let the container figure it out.
list<myobj> MyList;
MyList.push_back(NewObj);
MyList.sort();
There are performance issues of course if this is being updated frequently and a list may not be the best container, but just a thought.
|
|
|
|
|
I am in a very tight performance requirement here. I have about 20 incoming data structures per second and the list can be large. I was using a binary search to make a sorted insert into the list. But, the list.sort() approach will sort the whole list for each event, not something that will fir in my requirements.
The binary search method is efficient, but I wanted to find out if there are better methods available.
-Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
binary search works greate with arrays not lists.
because. . .
A list is a conected items in different blocks of memory , while an array is one big block of memory when the items stored one after one after one .
which means that,
to get 14th item from the array, you do this: ar[14]
ar[14] = (*(ar + 14 * sizeof(YourArrObj) ))
while to get 14th item from a list you will to get the 1st item and from there you'll get the 2nd item and then the 3rd and the 4th until you'll get the 14th item
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
Does anyone know how to add print preview support to an active document server?
|
|
|
|
|
Hello everyone,
I am new to C++/MFC so I hope someone can help me out here.
I'm writing a program which does things relating to various (human) languages. I would like the code which deals with each language (e.g. French, German, etc.) to be stored in a DLL. The main program will not know in advance which language DLLs exist, it will look in a folder to find them.
The task of the DLLs will be to operate on classes derived from CObject. Sometimes the DLLs will need to put up dialog boxes.
I have two questions:
(1) Would it be possible to have a class CLanguage in the main program, overridden by a class CFrench in the French DLL, to achieve all French-related functionality, by a class CGerman in the German DLL, etc. Then in the main program the user would pick a language and the main program would create a CFrench or a CGerman etc. as appropriate. This seems probably impossible to me because the main program cannot have access to the definition of a CFrench because it doesn't know in advance what languages exist. Is this correct?
(2) Suppose that is not possible, then no problem, I can do it another way: The DLLs would be required to export certain fuctions (e.g. InitLanguage, GetVerbList, etc) and the main program would dynamically load the dll and call the functions with GetProcAddress. In that case, do I need a regular DLL or an extension DLL? The exported functions in the DLL would have some parameters which are pointers to classes derived from CObject, and they would use MFC. But I can't work out from the documentation whether this means I need an extension DLL, and I don't really understand the difference between extension DLLs and regular DLLs.
If anyone can help, I will be really grateful.
best regards,
Stephen Wilson
UCLA Department of Linguistics
|
|
|
|
|
I'd look at creating them as COM DLL's. You could create a base interface such as ILanguage and have each DLL implement it. Choosing them would then be a matter of calling the right CLSID.
Maybe this will help, http://www.devx.com/free/mgznarch/vcdj/1997/aug97/extapp1.asp
It's not exactly what you want, but it might help.
Michael
|
|
|
|
|
Thanks Michael. I'm having a look at the page you suggested. I will consider using COM. However, I find it quite complicated and would like to see if I can get away with just using DLLs. But maybe COM is the better choice; I'm not sure.
best,
Stephen
|
|
|
|
|
Stephen,
About a year ago I set up a system very similar to what you are looking for. I created an abstract base class that defined the entire interface that I needed for the main program, then created a series of DLLs that implemented specific instances of the class.
Quick code :
class Base { // in file "Base.h", included into each DLL
public:
virtual void showMsg(string msg);
virtual string translateMsg(string msg);
};
Then create a "German.DLL"
...
class German : public Base {
public:
virtual void showMsg(string msg) { ... }
virtual strin translateMsg(string msg) { ... }
};
__declspec ( dllexport) Base* create();
...
And create a "French.DLL"
...
class French : public Base {
public:
virtual void showMsg(string msg) { ... }
virtual string translateMsg(string msg) { ... }
};
__declspec ( dllexport) Base* create();
...
In the main program :
...
void (create*)();
HMODULE lib;
// Create the required type of language by loading DLL and finding 'create' function
Base* language_;
switch (type) { // assume we have varialbe 'type' which tells us what we want
case GERMAN :
lib = LoadLibrary("German.dll");
create = GetProcAddress(lib,"create");
language = create();
break;
case FRENCH :
lib = LoadLibrary("French.dll");
create = GetProcAddress(lib, "create");
break;
}
language = create();
// and Use
string msg = language->translateMsg("Hello");
language->showMsg(msg);
...
This approach only works if the main prgram NEVER needs to call a class specific function - it can only ever call functions declared in the "base" class. It also has the advantage that you only need to export a single function from each DLL - the 'object factory'. This is all very similar in concept to COM, but much simpler to code. COM would be preferable if the application was (or could) be in another programming language.
You don't need to use extension DLLs - the differences are mainly to do with resource management. Unless you have a specific need, then 'standard' dlls will work fine.
Syntax is probably a bit rusty in the sample code. Hope this helps.
-------------------------
Reg : "Well, what Jesus blatantly fails to appreciate is that it's the meek who are the problem."
|
|
|
|
|
Thanks Mike, this looks like just what I need. As far as I understand, what I am trying to do is conceptually similar to COM, but I'm trying to get away without having to learn a whole new system, because I only want to use C++. Your approach will work because indeed the main program will only ever call a restricted, pre-determined set of functions defined in the base class.
So you say I don't need to use extension DLLs? Even if the Base class (from your example) is derived from CObject? And maybe some of the parameters of the derived functions will take pointers to MFC classes?
The reason I ask is the following from the documentation: "If you need to pass an MFC or MFC-derived object pointer to or from an MFC DLL, the DLL should be an extension DLL. The member functions associated with the passed object exist in the module where the object was created. Since these functions are properly exported when using the shared DLL version of MFC, you can freely pass MFC or MFC-derived object pointers between an application and the extension DLLs it loads." (from the "Extension DLLs" page of the VC++ docs.)
Is this not relevant to my case? If you could briefly explain, it would be very helpful.
thanks again,
best,
Stephen
|
|
|
|
|
Stephen,
I'd be lying to you if I said I understand the whole 'extension DLL' concept. I have read the same documentation you are quoting from, and it's obviously poorly written - it's quite common to derive objects from CObject and pass them into and out of DLLs. I do it all the time with CDialog derived classes. My guess is that this particular piece of documentation was written before (or without the knowledge of!) the whole "AFX_MANAGE_STATE" concept, which seems to be the key to allowing a 'regular' MFC DLL to import and export CObjects. The main difference (as far as I can see) between an extension DLL and a regular DLL is in the handling of resources. A regular DLL has it's own private resources - a dialog with an ID of "1000" can exist in two separate regular DLLs, and there will be no problems (provided the "AFX_MANAGE_STATE" rules are followed!). In an extension DLL, the resources are 'appended' to the apps resources, so you can get conflicts with ID ranges, etc.
There are also issues to be dealt with when mixing MFC objects and threading, so if a DLL wants to create it's own threads you need to be very careful in passing certain MFC objects between DLLs.
----------------
Reg : "Well, what Jesus blatantly fails to appreciate is that it's the meek who are the problem."
|
|
|
|
|
I am having some trouble with CFindAndReplace dialog. It appears that everything works until the point the dialog goes out of scope when it crashes.
According to documents, you have to instantiate the structure on the heap and then create the dialog which is what i do :
void LogDlg::OnCmdSearch()
{
if (!pFRDlg)
{
// Initialize find string
if (!szFRDlgFindString)
{
szFRDlgFindString = new char[256];
szFRDlgFindString[0] = 0;
}
// New find dialog
pFRDlg = new CFindReplaceDialog();
pFRDlg->m_fr.lStructSize = sizeof(pFRDlg->m_fr);
pFRDlg->m_fr.hwndOwner = this->GetSafeHwnd();
// Can't do up/down searches in RichEditCtrl?
pFRDlg->m_fr.Flags |= FR_HIDEUPDOWN;
pFRDlg->m_fr.lpstrFindWhat = szFRDlgFindString;
pFRDlg->m_fr.wFindWhatLen = 256;
pFRDlg->Create(TRUE, "", NULL, FR_DOWN, this);
}
}
After that, you have your search routine:
void LogDlg::OnFind()
{
if (pFRDlg->IsTerminating())
{
pFRDlg = NULL;
}
else if (pFRDlg->FindNext())
{
static bool InFindNext = false;
if (InFindNext)
return;
InFindNext = true;
CRichEditCtrl *pEdit = (CRichEditCtrl *)GetDlgItem(IDC_LOGVIEW);
FINDTEXTEX FindText;
pEdit->GetSel(FindText.chrg);
// Set text range appropriately....
// If it's empty, select the entire range
if (FindText.chrg.cpMin == FindText.chrg.cpMax)
{
FindText.chrg.cpMin = 0;
FindText.chrg.cpMax = -1;
}
// If there's selected text, read past it.
else if (FindText.chrg.cpMin >= 0 && FindText.chrg.cpMax > 0)
{
FindText.chrg.cpMin = FindText.chrg.cpMax;
FindText.chrg.cpMax = -1;
}
FindText.lpstrText = szFRDlgFindString;
for (;;)
{
// Did we find something?
if (pEdit->FindText((pFRDlg->MatchCase() ? FR_MATCHCASE : 0) |
(pFRDlg->MatchWholeWord() ? FR_WHOLEWORD : 0),
&FindText) != -1)
{
pEdit->SetSel(FindText.chrgText);
break;
}
// Looped?
else if (FindText.chrg.cpMin != 0 || FindText.chrg.cpMax != -1)
{
if (MessageBox(_T("End of text reached. Search again from the beginning?"), _T("Selection not found."), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
FindText.chrg.cpMin = 0;
FindText.chrg.cpMax = -1;
}
else
break;
}
// Nowhere in there
else
{
MessageBox(_T("No matching text found."), _T("Selection not found"), MB_OK | MB_ICONWARNING);
pEdit->SetSel(0, 0);
break;
}
}
InFindNext = false;
}
}
So, what else do i need to do, to prevent this thing from crashing? Do I need to clean up this thing somewhere? Am i missing something?
|
|
|
|
|
I want to have a certain control about ALL running windows of Internet Explorer.
For example I want to do my own things with the adress, if the user types in e.g. "g Something" (without quotation-marks), I want to navigate the browser to www.google.com and then search for "Something". (same as the browser Opera does)
How can I do this?
thanks in advance
|
|
|
|
|
Hi,
I'm working with a bitmap that is 1 bit. I need to find out if each bit is a 0 or a 1. Basically, I'm reading it in, one scan line at a time, for this example, let's say that it is 277 bytes wide. I do the following:
char* imageBytes = new char[277];
file.Read(imageBytes, 277);
for(int x = 0, x < 277; x++)
{
int indByte = imageBytes[x];
}
Can anyone help me to access each one of the bits to find out if it's black or white?
Thanks for any help you can provide,
Craig
|
|
|
|