|
You can use the COM ShellLinkObject to create shortcuts, and this only requires shell32.dll.
In an ideal world, things would be simple and you would just have to add a reference to shell32 in the VS.NET IDE, then start playing with the objects and interfaces.
Unfortunately, the actual IShellLink interface is not declared in the shell32 namespace. You'll find ShellLinkObject and ShellLinkObjectClass but they are worthless.
That's somewhat tough since you have to do the interop yourself, ie declare COM signatures. Here is how it goes :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IShellLinkA
{
void SetPath(string path);
void SetDescription(string path);
void Save(string where);
...
}
ShellLink c = new ShellLink();
IShellLinkA i = (IShellLinkA) c;
i.SetPath("ert");
...
That's just the begin of the code.
Be sure to read this reference MS article[^] (WIN32 C/C++ audience though).
|
|
|
|
|
i put in this :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IShellLinkA // Cannot list any base interfaces here
{
void SetPath(string path);
void SetDescription(string path);
void SetIconLocation(string path, int index);
void Save(string where);
void SetWorkingDirectory(string path);
}
and called this:
ShellLink c = new ShellLink();
IShellLinkA i = (IShellLinkA) c;
i.SetPath(@"c:\test.txt");
i.Save(@"c:\test.lnk");
but it doesn't work (the shortcut doesn't appear). And i don't quite understand some of the stuff/code on the link you gave me (mainly because it's in C/C++). Any help would be greatly appreciated.
|
|
|
|
|
In my code snippet, IShellLink was declared as a dual interface, although, after I have double checked it, it's only a IUnknown interface.
Here is the right declaration and code :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class SH
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IShellLinkA
{
void GetPath(string pszFile,
int cchMaxPath,
IntPtr pfd,
int fFlags);
void GetIDList(IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription(string pszName,
int cchMaxName);
void SetDescription(string pszName);
void GetWorkingDirectory(string pszDir,
int cchMaxPath);
void SetWorkingDirectory(string pszDir);
void GetArguments(string pszArgs, int cchMaxPath);
void SetArguments(string pszArgs);
IntPtr GetHotkey();
void SetHotkey(int wHotkey);
void Resolve(IntPtr hwnd,
int fFlags);
void SetPath(string pszFile);
}
SH c = new SH();
IShellLinkA i = (IShellLinkA) c;
...
UCOMIPersistFile p = (UCOMIPersistFile) i;
p.Save(@"c:\mylink.lnk",false);
|
|
|
|
|
Hi all
I need to pass a pointer to the a function that uses fread to read a file in memory. Unfortunaly MS decided to make the __UnmanagedMemoryStream internal. So now what I have done is to read all the data from a Stream object to a byte[]. Then pin it with a GCHandle and passing that pointer, freeing it after use. Now this works all nice and well, but I cant help to feel "duplication" occurs making this method rather inefficient for large files.
Any suggestions?
PS: from __UnmanagedMemoryStream I can get a GetBytePtr() value (via reading field value via reflection) which is exactly what I need (but this stream is only exposed via Assembly.GetManifestResourceStream). Damn you MS. I want this class!!!!!
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Hi all
SO I read this:
Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.
So now I have a assemblyname.dll.config file set as content, but its not outputted to the "output" directory.
Any suggestions?
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Hello,
As you might know CodeGuru is an excellent web site were tones of controls and software in general is posted for free.
For historical reasons the big majority of contributions are witten for MFC (VC 6.0), ATL, and alikes. If you surf it you'll colud find very valuable pieces of software.
Most of them come in files .h and .cpp that integrate smoothly whith an MFC app.
I would like to ask a question: Somebody knows a way or has tried to reuse this software from NET and C# using interop?
Thanks,
Josep L Colom
|
|
|
|
|
Basically most content from Cg and Cp don't expose (export) anything. They are classes to be added to your MFC-based VC++ projects. So that's a bit weird of a question.
With C#, I can't really figure out what you could do out of most "MFC controls" code in Cg and Cp, since interop only allows you to import dll functions, not classes. (I don't know if this has been improved with VS.NET 2K3).
With MC++, things get somewhat better. Watch out this article[^] (registration required).
That said, MFC has its use in his context ("old" C++), and Windows Forms is simply the de facto .NET UI framework to use.
|
|
|
|
|
One way to reuse I taught was (if possible, but I don't know how) to convert those .h/.cpp clas(ses) to an ActiveX control. May be creating a new MFC ActiveX DLL project, and then, through interop to access this ActiveX (COM object).
But may be I'm saying a nonsense thing..
|
|
|
|
|
Josep L Colom wrote:
One way to reuse I taught was (if possible, but I don't know how) to convert those .h/.cpp clas(ses) to an ActiveX control. May be creating a new MFC ActiveX DLL project, and then, through interop to access this ActiveX (COM object).
Although that's true in theory, since ActiveX type libraries can be imported in the .NET world, I believe you should engage this way only as last option. Reasons are :
- the marshaler (type library importer) has a few bugs, and as a consequence it's likely you have issues when calling exposed interfaces.
- you have to build the ActiveX first, which means you have to provide implementation for IOleClientSite and some other containers as well. Got my point ? You'll end drop dead before you get a simple MFC owner drawn derived control, working fine in the .NET world.
|
|
|
|
|
I though how it was really cool how I was able to just slap togeather a regular c# program in vs and just build it into an .aspx webpage with iis...
but all the sudden when ever I build my page and the browser comes up I can't see the forms or anything on my pages...
APS.NET is really cool and it's even cooler that I can make pages in C#...
What is wrong can somebody help a kid out?
/\ |_ E X E GG
|
|
|
|
|
There are many limitations for hosting form controls in IE. Odds are, you need to modify the programs permissions. Just run mscorcfg.msc and configure the assembly.
Hope it helps, else give more info.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
What do you mean
run mscorcfg.msc and configure the assembly.
I have no clue what your talking about.... try explaining it to me in 6th graders terms...
THANKS.
/\ |_ E X E GG
|
|
|
|
|
If you installed IIS after VS.NET you might have a problem with the aspnet_isapi.dll not being registered. Try running "regsv32 aspnet_isapi.dll" in the command window.
|
|
|
|
|
can you elaborate more I have no clue what your talking about.,....
/\ |_ E X E GG
|
|
|
|
|
I can try...
When you install IIS after you install VisualStudio, there might be a problem with the "connection" between the two. I had a problem with debugging asp pages, and IE did not display components, only HTML. To resolve this problem you can reinstall VS, but another way is to register the dll i mentioned. The command prompt is found under the start menu. Does that answer it? If not, specify what you dont understand.
|
|
|
|
|
im looking for a way to encrypt a file name..and still keep it a valid file name...and then beable to decrypt it just from the file name. I tryed using a RC2 encryption...and then coverting it to a base64 string but i get a error sometimes saying "could not find part of path name such and such".. is there another way to do this and still beable to decrypted the file name and return it to the original ?
Thanks Alot
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
I don't quite follow what you mean Jesse..
If you want to identify the file as being encrypted, you could just add your own unique extension on the end:
document.doc -> document.doc.enc -> document.doc
Then remove it when decrypting using the Path class to strip off your added extansion. This way there's no need to store any filename info in the encrypted data at all.
However, if you want to store the original filename in the encrypted stream, replacing with something totally unrelated like this:
document.doc -> encrypted.file -> document.doc
Then it's going to be a little trickier. What you need to do here is use the Path class the get just the filename (not the whole path) of the source file, then store the length of the filename string in the encryption stream, followed by the string name itself as bytes. When decrypting, you will need to read your filename length first, then read that amount of bytes to re-create the filename, then read & decrypt the actual file data.
|
|
|
|
|
thanks furty i found something that fixed the problem for me using RC2 and memory streams... i used that path class...and sent just the name to the seperate "class" where the name was encrypted and then returned.... apon decryption i send the "encrypted" name back...and it decrypted that string using the same password... you were write on the last part.. i just had no idea how to do it because when i did it...it would encrypt the string and return a name that was too long...for a valid windows file name. the following code encrypted the string and fixed the problem...
thanks... Jesse M
please keep in mind this encryption method i know isnt the correct way to do it...but its just for a file name.. so i did it the easyiest way =)..
public string FilterInName(string pToEncrypt){<br />
try{<br />
if(pToEncrypt.Length<=3){<br />
<br />
return pToEncrypt;<br />
}<br />
string sKey = "alPhatab";<br />
DESCryptoServiceProvider des = new DESCryptoServiceProvider();<br />
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);<br />
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);<br />
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);<br />
MemoryStream ms = new MemoryStream();<br />
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),<br />
CryptoStreamMode.Write);<br />
cs.Write(inputByteArray, 0, inputByteArray.Length);<br />
cs.FlushFinalBlock();<br />
<br />
StringBuilder ret = new StringBuilder();<br />
foreach(byte b in ms.ToArray()){<br />
ret.AppendFormat("{0:X2}", b);<br />
}<br />
return ret.ToString();<br />
}catch(Exception ){return pToEncrypt;}
The Code Project Is Your Friend...
|
|
|
|
|
It seems that it's not possible, to fit a Windows Form in a Control (such as a Panel, for instance). I can think of a few good reasons why that's true, but I'm just doublechecking. It'd be pretty handy for me if I could fit a Form in a Control, so I don't have to replicate many things; MDI Forms in a Control would be even nicer.
|
|
|
|
|
Here's very quick fix (one I remember Paul Watson enjoyed):
Let your form inherited from UserControl instead (mite need 1 or 2 changes). Then just drop that in a form with filled docking.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
There are at least two ways to go about it, the first is the best way if you can modify the design which you have given above.
The second is what you'll have to do if you have no choice but to leave it as a Form. You won't get any design time support for it either, but something is better than nothing
Since the Form class inherits ultimately from the Control class it is possible for a Form to be added as a child control.
To do this, first create an instance of the Form (MyForm mf = new MyForm() ). Now set any properties you want on it, especially the Location , and Size properties. Now set the TopLevel property of the form to false (mf.TopLevel = false ). You may or may not see this property in the IntelliSense pop-up, don't worry it is there
Now add the form to the Controls collection, Controls.Add( mf ); . Lastly you need to make the form visible, mf.Visible = true .
All together now:
MyForm mf = new MyForm();
mf.Location = new Point( 8, 8 );
mf.Size = new Size( 150, 300 );
Controls.Add( mf );
mf.Visible = true;
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Just some dry, semi sober humor for you folks
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
|
Go unsafe
Also post some code and give an explanation of the unmanged function you are trying to use. Your bets are string and StringBuilder, depending on the situation.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
see title
I see dumb people
|
|
|
|