|
You dont need to do any test for OS just call
CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLinkW,
(void**) &pShellLink);
if it succeedes use the IShellLinkW interface.
If it fails create the IShellLinkA interface.
|
|
|
|
|
I am impressed! I must admit that I did not think of this as a switch instead of a switch based on the operating system.
i will write a demo program and post it and see if what happens--let you know in a little while.
By the way--this is a BRILLIANT suggestion to first try for IID_IShellLinkW and if it fails use IID_IShellLinkA.
And I might point out that in all the samples of code to create links, nobody has thought to do this!
Bill SerGio, The Infomercial King
|
|
|
|
|
I had a similar problem once - I had to call a Windows 2000 machine but I was developing on NT. The solution (in pseudocode) was something like this:
if(IsOs2000())
{
Explicitly load the system DLL that has the function
using LoadLibrary
Get the function poitner using GetProcAddress
Call the function
Unload the DLL if necessary
}
Just a thought. Ugly, I know, but it might work in your situation.
Even if you win the rat race, you're still a rat.
|
|
|
|
|
Am i missing something? Why doesn't IShellLinkA work on both '98 and 2k? They both work on XP AFAIK.
--------
Have you hugged your monitor today? --Shog9 --
|
|
|
|
|
Email me a release to test please Shog,
It might be Bill's 2000 has a problem.
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
More about me
|
|
|
|
|
It ONLY works only Windows 98 and I was surprised to learn this as you are!
If you set _UNICODE, and compile it under UNICODE, as a SEPARATE exe or DLL then it works ONLY on Windows 98.
So far, nobody has created a class or piece of code that will compile and create a SINGLE exe or DLL that works on BOTH Windows 98 and Windows 2000.
Bill SerGio, The Infomercial King
|
|
|
|
|
Please excuse my type...
i meant...
If you set _UNICODE, and compile it under UNICODE, as a SEPARATE exe or DLL then it works ONLY on WINDOWS 2000.
Bill SerGio, The Infomercial King
|
|
|
|
|
I'm confused,
Shog9's app work on my Win 2000 and 98 for me.
Have you mangled your 2000 ?
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
More about me
|
|
|
|
|
I have looked at every sample of source code i could find on creating Links on the Desktop and EVERY piece of sample code FAILS to create links on Windows 2000--except for those samples that include a separate UNICODE version of the code.
Now it is VERY inconvenient to have to include 2 versions of a program, one in ASCII and another in UNICODE. So what's the answer?
I will offer 2 solutions to this problem that I originally proposed in the "Lounge" where I was told was the wrong place to post anything important or serious!
The first solution is to create 2 versions of your code, and include BOTH versions as a resource in your application and launch the correction version from your program based on the Windows Platform. This works but is not elegant at all--it is the solution that i believe is used by BOTH InstallShield and WYSE Installers! No wonder their exe files are so big!
The other solution I offer below. I believe it will work if compiled on Windows 2000. And it would be nice if someone with Windows 2000 could let me know if it works?
I develop on Windows 98 using Visual Studio 6...
#include "direct.h" /* This is needed for _mkdir */
#include "objbase.h"
#include "shlguid.h"
#include "wchar.h"
#define INITGUID
#include "initguid.h"
//#define INC_OLE2
//#pragma comment( lib , "OLE2")
//#include "ole2.h"
//#include "comcat.h"
//#include "olectl.h"
Where UINT uLinkLoc = CSIDL_DESKTOP;
Is there a way to write a SINGLE class that can create a link on the Desktop in both Windows 98 and Windows 2000 without compiling 2 separate versions(one UNICODE and one ASCII)???
bool CInstall::CreateShortCut( LPCSTR lpszSourceFile,
LPCSTR lpszSourceDir,
UINT uLinkLoc,
LPCSTR lpszDesc,
bool IsFolder )
{
HRESULT hResult = NULL;
IShellLink* pShellLink = NULL;
bool rc = false;
LPCSTR lpszDestination = NULL;
ITEMIDLIST *id = NULL;
TCHAR szLinkLoc[MAX_PATH] = "";
TCHAR szShellPath[MAX_PATH] = "";
CString sLinkLoc;
sLinkLoc.Empty();
CString sLink;
sLink.Empty();
// Initialize IShellLink interface
hResult = CoInitialize(NULL);
// Get pointer to IShellLink Interface
hResult = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink,
(void**) &pShellLink);
if (SUCCEEDED(hResult))
{
//Cache, Fonts, History, NetHood, Personal, Printhood, Programs,
// Recent, SendTo, Start Menu, Startup, Templates, ShellNew
if (uLinkLoc == CSIDL_APPDATA) {
sLinkLoc = "AppData";
} else if (uLinkLoc == CSIDL_COOKIES) {
sLinkLoc = "Cookies";
} else if (uLinkLoc == CSIDL_DESKTOP) {
sLinkLoc = "Desktop";
} else if (uLinkLoc == CSIDL_STARTMENU) {
sLinkLoc = "Start Menu";
} else if (uLinkLoc == CSIDL_STARTUP) {
sLinkLoc = "Startup";
} else if (uLinkLoc == CSIDL_FAVORITES) {
sLinkLoc = "Favorites";
}
if (sLinkLoc.GetLength()>0) {
GetShellFolderPath(sLinkLoc, szShellPath);
sLink = szShellPath;
} else {
SHGetSpecialFolderLocation(NULL, uLinkLoc, &id);
SHGetPathFromIDList(id, szLinkLoc);
sLink = szLinkLoc;
}
sLink += "\\";
sLink += lpszDesc;
sLink += ".lnk";
lpszDestination = (LPCSTR)sLink;
if (IsFolder) {
// Requies: #Include
hResult = _mkdir(lpszDestination);
// Clean up
pShellLink->Release();
CoUninitialize();
if (SUCCEEDED(hResult)) { return true; } else { return false; }
}
IPersistFile* ppf = NULL;
// Set path to shortcut target
pShellLink->SetPath(lpszSourceFile);
// Add Start Directory
if(lpszSourceDir)
hResult = pShellLink->SetWorkingDirectory(lpszSourceDir);
// Add Description
if(lpszDesc)
hResult = pShellLink->SetDescription(lpszDesc);
//if(lpszArguments) { hResult = pShellLink->SetArguments(lpszArguments); }
//if (lpszIconLocation) { hResult = pShellLink->SetIconLocation(lpszIconLocation, nIconIndex); }
//if (Show != -1) { hResult = pShellLink->SetShowCmd(Show); }
//if (HotKey != 0) { hResult = pShellLink->SetHotkey(HotKey); }
//if(nIconIndex!=(UINT)-1) { hResult = pShellLink->SetIconLocation(lpszSourceFile,nIconIndex); }
// Query IShellLink for IPersistFile interface
// for saving shortcut in persistent storage
hResult = pShellLink->QueryInterface(IID_IPersistFile, (void**) &ppf);
if (SUCCEEDED(hResult)) {
WORD wszWideString[_MAX_PATH+1];
// Ensure that string is ANSI
//MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,szLink,-1,wsz,sizeof(wsz));
MultiByteToWideChar(CP_ACP, 0, lpszDestination, -1, wszWideString, _MAX_PATH+1);
// Save link by calling IPersistFile::Save.
hResult = ppf->Save(wszWideString, TRUE);
ppf->Release();
rc = true;
SHChangeNotify(SHCNE_ALLEVENTS, SHCNF_IDLIST, &pShellLink, 0);
}
// Clean up
pShellLink->Release();
CoUninitialize();
}
return rc;
}
Bill SerGio, The Infomercial King
|
|
|
|
|
I forgot to include one of the functions that I call in the code sample above and I am including it below.
bool CInstall::GetShellFolderPath(LPCSTR lpShellFolder, LPSTR lpShellPath)
{
//lpShellFolder can be one of the following
//AppData, Cache, Cookies, Desktop, Favorites, Fonts, History, NetHood,
//Personal, Printhood, Programs, Recent, SendTo, Start Menu, Startup,
//Templates, ShellNew
DWORD rc;
DWORD length = MAX_PATH;
DWORD type = REG_SZ;
HKEY hkey;
rc = RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
0,
KEY_READ,
&hkey);
if (rc == ERROR_SUCCESS)
{
rc = RegQueryValueEx(hkey,
lpShellFolder,
NULL,
&type,
(BYTE *) lpShellPath,
&length);
RegCloseKey(hkey);
}
if (rc == ERROR_SUCCESS)
return true;
else
return false;
}
Bill SerGio, The Infomercial King
|
|
|
|
|
Have not tested, but if you say a UNICODE build will work
it is maybe because there are 2 IShellLink interfaces, one
IShellLinkA and one IShellLinkW, and if that happens to be
the case you could build an ANSI app and use IShellLinkW and get
it to work
|
|
|
|
|
So if this is the case, then:
if (b2000 || bNT) {
// Call "IShellLinkW"
}
else {
// Call "IShellLinkA"
}
Is this what you had in mind to build 2 versions in one class?
What I don't understand is why hasn't anyone posted a sample of this code before?
Bill SerGio, The Infomercial King
|
|
|
|
|
I was thinking, just query for IShellLinkW, if you get it, use it.
Otherwise use IShellLinkA.
|
|
|
|
|
Anyone know ehre to get some ASPI documentation?
Thanks in advance.
|
|
|
|
|
|
I was just wondering if there was a way to turn on and off the keyboard lights for CapsLock, NumLock and ScrollLock programmatically.
any help appreciated
"When a friend hurts us, we should write it down in the sand, where the winds of forgiveness get in charge of erasing it away, and when something great happens, we should engrave it in the stone of the memory of the heart, where no wind can erase it" Nish on life [methinks]
"It's The Soapbox; topics are optional" Shog 9
|
|
|
|
|
What! Brian Delahunty is asking a programming question
Look here. Clickety
I have never wasted time worrying about such insignificant things. Keep your eye upon the donut and NOT upon the hole. - Bill Sergio in The Lounge - June 23, 2002
|
|
|
|
|
Thanks I should have known that!!!!!!!!!
"When a friend hurts us, we should write it down in the sand, where the winds of forgiveness get in charge of erasing it away, and when something great happens, we should engrave it in the stone of the memory of the heart, where no wind can erase it" Nish on life [methinks]
"It's The Soapbox; topics are optional" Shog 9
|
|
|
|
|
How can I get the style of a window class.
Ex: I have a window (handle=0x00000b94, class name=#32770(dialog) )
I want to get the styles and extended styles of it as CS_DBLCLKS, WS_EX_CLIENTEDGE....
How can I do that ?
I try this way:
LONG lStyles=::GetWindowLong(hwnd,GWL_STYLE);
LONG lExStyles=::GetWindowLong(hwnd,GWL_EXSTYLE);
CString strStyles;
if ((lStyles&BS_OWNERDRAW)==BS_OWNERDRAW)
strStyles+="BS_OWNERDRAW";
if ((lStyles&CS_VREDDRAW)==CS_VREDDRAW)
strStyles+="CS_VREDDRAW";
...
...
(hundreds of "if" !!!!!!!!!!!!!!!)
Help me !
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
dlhson wrote:
extended styles of it as CS_DBLCLKS, WS_EX_CLIENTEDGE
First off the CS_DBLCLKS is a CLASS style, not a window style
the GetWindowLong, using the GWL_STYLE or GWL_EXSTYLE will only return you the window styles (i.e. WS_XXX ,or WS_EX_XXX)
for CS_XXX you need to call GetClassLong( hwnd, GCL_STYLE )
As far as conmverting them to a string, I think you are stuck with a big if/else statement, sorry !
|
|
|
|
|
Dear All,
how can i solve the problem of including the View class header file in the MainFrame.cpp file. when do so an error occure about the GetDocument(); declaration in the view header file.the error says "error C2143: syntax error : missing ';' before '*'"
thanks,
Mohammad Zakarni
|
|
|
|
|
You need to include the document class as well. The error is because GetDocument returns a pointer to a document object, so you need to include it first, so it knows what that is.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|
Cool thank you it worked...
Thanx;)
|
|
|
|
|
I got the same error C2143 when I moved a snippet of working code to open a file and load a list box. I put the code in a new file as a good programming practice and I think the error was related to the include header:
#include <fstream>
using namespace std;
Any suggestions?
When you come to a fork in the road, take it! Y. Berra
|
|
|
|
|
doubl00 wrote:
#include
using namespace std;
Any suggestions?
1. Check 'display this message as is' or use < and > to do < >
2. NEVER use all of namespace std.
3. I really don't know, because I don't know what you included. The problem will be different now, because it's obviously std library stuff you're using. Could you post the offending code and the name of the header ?
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
|
|
|
|
|