|
You could make Open(blah) a function of your application class.
Then your DLL would get a pointer to that application object and you could call Open(blah) via that pointer. The list would then sit in the application and the dll would not need to know about foreign memory.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Dangleberry wrote:
How can I make it so that the io class is a system wide static class so that any instance within the current process can access the same static data?
You can only do that by making its members non-static, and creating an instance of it in your application, then passing that instance to your DLL so that you application and DLL use the same instance of the class.
The fact that the members are static is only important at compile time. The DLL and application are compiled separately, and so they both get copies of the static data.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Yeah this is the way I was going to do it, but if I have multiple dll's for say different aspects of the app I'm going to have to distribute the pointer everywhere. I have managed to find an article on data_seg which allows static variables to share a common place in memory, but I have not yet managed to get it to work. I'd like it so that if I call io::Open() in my app or in any dll the same instance of io (and its static data members) are used in the function (can I actually pass an instance of a static class through and assign it to the dll instance?). I know I could pass a pointer through and use io->Open but I prefer the static function approach. Thanks for all responses, much appreciated.
|
|
|
|
|
Dangleberry wrote:
if I have multiple dll's for say different aspects of the app I'm going to have to distribute the pointer everywhere.
Unfortunately, thats the price to pay for wanting a centralised way of working with things.
Dangleberry wrote:
I have managed to find an article on data_seg which allows static variables to share a common place in memory, but I have not yet managed to get it to work.
Creating a shared data segment? I think that only works for multiple instances of the same DLL.
Basically, I think you'll find that the only way you can do it is by passing a pointer to an instance of the class to all your DLLs.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
If you use MFC compatible dll don't forget to call:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
Vitali
|
|
|
|
|
Hi,
I've (finally) succeeded in generating a dialog box for selecting directories, but I'm getting an error:
First-chance exception at 0x70bf6827 in F2F.exe: 0xC0000005: Access violation writing location 0x0063b058.
Unhandled exception at 0x70bf6827 in F2F.exe: 0xC0000005: Access violation writing location 0x0063b058.
The thread 'Win32 Thread' (0x54c) has exited with code 128 (0x80).
The thread 'Win32 Thread' (0x57c) has exited with code 128 (0x80).
The program '[784] F2F.exe: Native' has exited with code 128 (0x80).
This is my code, can you tell me what's wrong:
void IO_scherm_multiinput::OnBnClickedButton1()<br />
{<br />
<br />
<br />
BROWSEINFO* b=new BROWSEINFO();<br />
LPTSTR buf="Undef BE";<br />
<br />
int image=-1;<br />
b->hwndOwner=this->m_hWnd;<br />
b->iImage=image;<br />
<br />
b->lpszTitle="Please select a driectory for IO";<br />
b->pidlRoot=NULL;<br />
b->pszDisplayName=buf;<br />
<br />
b->ulFlags=BIF_BROWSEINCLUDEFILES;<br />
LPITEMIDLIST x=SHBrowseForFolder(b);<br />
<br />
}
|
|
|
|
|
Your display name buffer is probably being overrun. The SHBrowseForFolder() function assumes that pszDisplayName is MAX_PATH characters long, whereas in your code it is only 9 characters long. Do it like this:
void IO_scherm_multiinput::OnBnClickedButton1()
{
BROWSEINFO* b=new BROWSEINFO();
LPTSTR buf=new TCHAR[MAX_PATH];
_tcscpy(buf, "Undef BE");
int image=-1;
b->hwndOwner=this->m_hWnd;
b->iImage=image;
b->lpszTitle="Please select a driectory for IO";
b->pidlRoot=NULL;
b->pszDisplayName=buf;
b->ulFlags=BIF_BROWSEINCLUDEFILES;
LPITEMIDLIST x=SHBrowseForFolder(b);
delete [] buf;
} Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thanks a lot, this works ;P
Can you tell me too how to retrieve the selected directory from the x variable ? (the x as described in your code; I copied it)
|
|
|
|
|
SHGetPathFromIDList() should help
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
To make things easier, cou could allocate your BROSEINFO on the stack and hand the address over to SHBrowseForFolder(). Also, zeroing the structure is a good practice to make clear which pointers have been set and which not.
I did include Ryan's fixes for your buffer memory issues in this version.
void IO_scherm_multiinput::OnBnClickedButton1()
{
BROWSEINFO b = {0};
LPTSTR buf=new TCHAR[MAX_PATH];
_tcscpy(buf, "Undef BE");
int image=-1;
b.hwndOwner=this->m_hWnd;
[...]. b.pszDisplayName=buf;
b.ulFlags=BIF_BROWSEINCLUDEFILES;
LPITEMIDLIST x=SHBrowseForFolder( &b );
delete [] buf;
}
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
For NT4 I programmed a service which do some Hardware access and tranfer these data to an MFC Applikation. The transfer is done via Filemapping and eventhandling. This works very fine on several NT4 systems. Now we changed the system to XP. Installing and starting the service was no problem. When the applikation where started, it takes up to 30 seconds until one communikation with the service is done. After 2..3minutes the communication seens to be ok.
We use a very powerful PC and the systemload is below 20%
Has anyone an idea ?
regards Andreas
Andreas Zaum
|
|
|
|
|
Hello,
Check hardware access speed under XP...
Dificult say more without more details.
Vitali
|
|
|
|
|
I did know the answer once upon a time but can't for the life of me remember.
How can I ensure that implicitly linked (at compile time) are loaded in a particular order. I have to have time to read the registry in the App's InitInstance before one of the DLLs is loaded.
Happy programming!!
|
|
|
|
|
I doubt that order is going to help you here. All of the implicitly linked DLL's will be loaded before the call to your App's InitInstance takes place. If your program requires to read data from the registry before a DLL is loaded, then you will have to Load/Free the DLL in your code.
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
Oh and for those that ask programming questions in the lounge. Seek the truth here[^].
|
|
|
|
|
The DELAYLOAD linker option, perhaps?
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
Hi,
I am writing a small program with some zip archiving functionality (using the ZipArchive library from www.artpol-software.com). I would like to add a list box to one of the dialog boxes and a browse button for multiple file selection, but am not sure how to go about multiple file selection at all. I would like it so that the user can click on the Browse... button and select any number of files. Upon clicking "open", the list of files will then appear in the list box above the browse button (and the list must be stored so that when the user clicks on "Zip", all of those files will get zipped up). I would also like to make it so that the user can select all of the files in the list box, or select and remove individual files... However, I am getting ahead of myself with that. First, I need to find out how to create a multiple selection procedure. (I am of course using the Windows API and *no* MFC.)
The following code opens a Browse box which allows users to select multiple files (using OFN_EXPLORER and OFN_ALLOWMULTISELECT):
[code]
BOOL OpenMultipleFiles(CHAR *filename, int len, HWND hWnd)
{
OPENFILENAME files;
ZeroMemory(&files, sizeof(OPENFILENAME));
files.lStructSize = sizeof(OPENFILENAME);
files.hwndOwner = hWnd;
files.lpstrFilter = "All Files (*.*)\0*.*\0\0";
files.lpstrFile = filename;
files.nMaxFile = len;
files.lpstrTitle = "Select Files";
files.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
return GetOpenFileName(&files);
}
[/code]
This allows multiple section, though I am not sure what to do with the returned string, nor whether I am doing it right, as I have just modified the above code from code designed for opening a single file.
I managed to find the following code, designed to get the information returned from a multipe file selection box, from http://www.angelfire.com/biz/rhaminisys/tricks.html:
[code]
if ( ofn.nFileOffset < lstrlen(Buffer) )
AddToFileList( Buffer );
else
{
strcpy( FilePath, Buffer );
FilePath[ofn.nFileOffset] = 0;
while ( Buffer[ofn.nFileOffset] != 0 )
{
strcpy( Message, FilePath );
strcat( Message, "\\" );
strcat( Message, Buffer+ofn.nFileOffset );
AddToFileList( Message );
ofn.nFileOffset += (strlen(Buffer+ofn.nFileOffset) + 1);
}
}
[/code]
Unfortunately, I have no idea of how to put all this code and information together! For a start, "Buffer" in the above code is a buffer designed to hold all of the file names. But I have no idea how to define buffer. EG:
char Buffer[MAX_PATH];
doesn't work, because MAX_PATH is not big enough to hold the names of, say, 50 odd files plus a filepath.
If anyone could tell me how I could create a multiple file selection function that allows my users to select a number of files for inclusion in their .zip file, and a function that then allows me to access the returned information (ie. getting the names of all the files individually), I would be really, really grateful. (One thing that occurs to me is that wouldn't using ofn.nFileOffset only work when first selecting the files, and not later when I need to get all the file names for zipping?)
Oh, and I am a novice at this stuff, btw, so if you can see I'm heading down the wrong path completely, please tell me, and feel free to overexplain as though I were an idiot.
Many thanks,
KB
|
|
|
|
|
void OnBrowse( void )
{
OPENFILENAME files = {0};
char szBuffer[32000] = {0},
szMessage[MAX_PATH],
FilePath[MAX_PATH];
files.lStructSize = sizeof(OPENFILENAME);
files.hwndOwner = GetSafeHwnd();
files.lpstrFilter = "All Files (*.*)\0*.*\0";
files.lpstrFile = szBuffer;
files.nMaxFile = sizeof(szBuffer);
files.lpstrTitle = "Select Files";
files.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
if (GetOpenFileName(&files) == TRUE)
{
if (files.nFileOffset < lstrlen(szBuffer))
m_lbFiles.AddString(szBuffer);
else
{
strcpy(FilePath, szBuffer);
FilePath[files.nFileOffset] = 0;
while (szBuffer[files.nFileOffset] != 0)
{
strcpy(szMessage, FilePath);
strcat(szMessage, "\\");
strcat(szMessage, szBuffer + files.nFileOffset);
m_lbFiles.AddString(szMessage);
files.nFileOffset += (strlen(szBuffer + files.nFileOffset) + 1);
}
}
}
}
|
|
|
|
|
Hi,
Many thanks for this!
Unfortunately, I'm getting a few errors:
GetSafeHwnd() is an undeclared identifier...
m_lbFiles is an undeclared identifier...
How do I declare these to get it to work? (Sorry if this is really obvious to you but I am still a novice.)
Presumably (if I can work out how to define it), m_lbFiles is a list of all the filenames selected, is that right? How would I then use that file list?
Sorry again for the dumb questions.
Many thanks,
KB
|
|
|
|
|
Kayembi wrote:
GetSafeHwnd() is an undeclared identifier...
It is a method of CWnd. If you are not using MFC, just use whatever window handle is appropriate.
Kayembi wrote:
m_lbFiles is an undeclared identifier...
It is a control variable for a listbox. Again, this is an MFC thing. You can add items to a listbox without MFC by using SendMessage(hwnd_of_listbox, LB_ADDSTRING, 0, (LPARAM) string_to_add) .
Kayembi wrote:
Sorry again for the dumb questions.
Just because you are a beginner does not make the questions dumb.
|
|
|
|
|
Ahhh... (Slaps forehead with palm)... That works perfectly, thank you! Now I have multiple files selected and displayed in a listbox.
Presumably to then use this list and zip up the selected files, I just use LB_GETCOUNT and then use LB_GETTEXT in a while() loop until all files from the list have been added... That should be fairly straightforward.
All I have to figure out then is how to store the list in a file (so that projects can be saved and loaded, ie. so the list can be reloaded into the listbox).
Many, many thanks for your help - I've spent ages trying to work this out, and you've got me up and running within a couple of hours.
Cheers,
KB
|
|
|
|
|
Hi,
This is probably going to seem a very dumb and easy question to many (I hope!), but I am a novice with C++ so please bear with me...
I have an application that saves certain settings to file, and loads them on opening. All of these settings are just simple strings and integers, so at the moment I just save them to a (renamed) INI file using WritePrivateProfileString() and load them using GetPrivateProfileString() and GetPrivateProfileInt(). However, using these instructions means that anyone using my program can open the INI file in a text editor and look at the stored information. Ideally, I would like to create saved files that can't be opened in a text editor.
Could anybody tell me how to do this, please? (I am using the Windows API but *not* using MFC.) If somebody could show me a function (or tell me where to look) that creates a save file, and then can save strings and integers to it, and also a function on how I would then read the information back (load it), I would be very grateful. (One advantage with using the PrivateProfile functions is that I can read whatever value I want arbitrarily without having to load the info of the whole fle - can this functionality be maintained in a custom file?)
Many thanks,
KB
|
|
|
|
|
CreateFile in MSDN has all your answers for creating and opening files. WriteFile and ReadFile can do just what you want with them. When you master that, get onto File Mapping in memory for fast access to file data
|
|
|
|
|
I think you can use register after i watched your requirement .
i'm a software engineer
|
|
|
|
|
Kayembi wrote:
However, using these instructions means that anyone using my program can open the INI file in a text editor and look at the stored information.
Is this a bad thing? If the settings are related to your application, what's the harm?
Ideally, Win32 programs use the registry instead of text-based INI files. It's no more secure, at least not to any experienced person, but it does give your application more flexibility.
|
|
|
|
|
Thanks for the replies.
I can live with INI files - it's not really a bad thing - but I just think it would be a little more "professional" if people can't look in the file. Also, I may need to store a password in there, in which case (although I could encrypt it in an INI file), a non-readable file would be better.
Thanks again for the replies, I'm looking into all the suggestions on the MSDN site and trying to work it all out... It's still a bit complex for me as I'm still learning, but I'm trying...
Cheers,
KB
|
|
|
|
|