SHBrowseForFolder looks like it may be my only choice. Is there a better way to have the user select a directory (other than, of course, writing my own)?
SHBrowseForFolder looks like it may be my only choice. Is there a better way to have the user select a directory (other than, of course, writing my own)?
How do you define "better"?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
One line of code in place of three. Please correct me if I'm wrong, but one needs to call CoInitialize() before and CoUninitialize() after to get it to work correctly. Also, I'm kinda confused as to why there is a return value of PIDLIST_ABSOLUTE when MSDN specifies that one must pass the pointer location of at least MAX_PATH to BROWSINFO.pszDisplayName for the return folder name.
Oh screw!! It uses DLLs. . . Crap crap crap crap crap!!!!
There _HAS_ to be a better way. . . anyone?
Every application that uses this particular sort of folder selection box uses SHBrowseForFolder - unless they use some wrapper around it. (Which might exist - search the web.)
Regarding Co*, you call CoInitialize at the start of your application and CoUninitialize at the very end, not before and after every call to SHBrowseForFolder.
The documentation about the whole thing IS confusing, I'll give you that.
I have an old project that uses the function, but I won't have access to it for another week.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Here is a SHBrowseForFolder sample.
Is that really your logic?Oh screw!! It uses DLLs. . . Crap crap crap crap crap!!!!
There _HAS_ to be a better way. . . anyone?
I wouldn't want to disappoint you, but most (if not all) functions of the Win32 API are located in DLLs (kernel.dll, user32.dll ...)
Ah, the way to explicitly say to the compiler, "Hey, I'm using these DLLs." This is my first tour in Windows programming. In Linux, when I need a runtime library, that GCC doesn't already know exists, I just -L the sucker. I didn't know how in Windows. . . which is why I said:Originally Posted by anonytmouse
So, yes, it _WAS_ my logic, however, now that I know how to use the DLLs it isn't so much a pain for me anymore.Originally Posted by Tonto
True, however, much unlike (as far as I have seen) Linux, there has to be some explicit coding (or is there some type of linker commands to make it look at a specific DLL) to make the compilier know that I want a specific run-time library/DLL. . .which ever way you want to look at it. On my Linux boot, I installed the library and compiler. GCC on my Linux boot knows about all my libs and will dynamically link to anything it needs based upon my #include's (except, of course, if I add a library later, then it goes back to the -L again).Originally Posted by Desolation
I had found a thread that stated the way to use a DLL was something along these lines:
Which is in C++, however, I thought that this was the way to do it. . . hence the "crap" as I had not yet found the way to go from the LoadLibrary() and the GetProcAddress() to CoInitialize() and CoUnInitialize(). And, I hoped there was a better way.Code:int main(int argc, char* argv[]) { hinstDll = LoadLibrary((LPCTSTR)"DGDLL.dll"); if(hinstDll==NULL) cout<<"FAILD TO LOAD THE DLL"<<endl; hShellHookProc = (HOOKPROC)GetProcAddress(hinstDll,"ShellProc"); if(hShellHookProc != NULL){ SetWindowsHookEx(WH_SHELL, hShellHookProc, hinstDll, 0); }else{ cout<<"FAILD TO CONNECT TO THE DLL FUNCTION"<<endl; } return 0; }
But, looks like anonytmouse's example with the #pragma comment(lib, "shell32.lib") is a better way.
EDIT: I assume that this pragma command tells the linker if you cannot find a function that is listed in this code, assume that it is from "shell32.lib" and check there before ditching out?
Thanks for all your help, anonytmouse!!
That command links the library shell32. However, it only works under MSVC. Otherwise, you'll need to go in your project settings and then something like 'dependencies' or 'linking options'. You don't need to do all of that. I only use this method when working with plug-ins.
Good, I'm not completely brain-fried. I noticed that in Code::Blocks, that pragma command didn't work. I've been looking (for the past hour or so) as to how to pass to gcc (or whatever linker gcc is actually calling on my machine) to use these DLLs. Would any of you be so kind as to let me in on the secret? Like I said, I've been searching for the past hour and haven't had any luck yet.
EDIT: Ugh. . . I just found this. Is that what I have to do to get the ole32 and system32 DLLs usable in my program? . . . or, again, is there a "better" way?
Last edited by Kennedy; 09-20-2006 at 11:44 AM.
Okay, I'm apparently thick. . . but I don't know that understand:
Does this mean that I have to reconstruct the lib file from the DLL file then link using the new reconstructed lib file. . . THEN. . . this would create an executable that would NOT have linked in the lib file, but would rather, using the system DLL path, search the system for the approiate DLL file and call that. . .Originally Posted by MinGW Website
OR. . .
Does this mean that now I have that section of the DLL statically linked into my code? . . . and if this is true does this stomp the rules for MS developement????
Sorry folks, I'm not intentionally thick. . . it is just that this is my first venture into a GUI on Windows. . . I'm used to Textual GUIs and XWindows. . . I'm not used to the Win32 API/Win programming. . . yet.
Found it. . . I was just being thick. . .
Essentially, all I have to do is -lole32
I did try it everywhich way, but that one. . . -lole32.dll doesn't work .
Just 'FYI', you don't link to dll's (dymanic link libraries), you link to static normal libraries, object files, and import libraries (which give you access to dynamic libraries' functions).
Hmmmm. . . I did. . . and it worked. So, I guess the next question is: How am I supposed to link to DLLs?