|
I am trying to write a wrapper to some VB6 code in C#. The problem is the VB6 code wants to return a Variant. How do you handle this in C#?
Example:
[VB6]
Dim pixels As Variant<br />
pixels = pixelBlock.SafeArray(0)
[C#]
? = pixelBlock.SafeArray(0);
Mark Sanders
sanderssolutions.com
|
|
|
|
|
object pixels = pixelBlock.SafeArray(0);
is the direct traslation.
You could probably also use
System.Array pixels = ...
or if you know the type of the array, you might get away with
MyType[] pixels = (MyType[]) ...
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
I'm sure this is totally documented and I am just looking / searching for the wrong things here - if some kind soul can point me to the right documentation, then I'm sure I can work it out for myself.
I want to add a new element to the Windows Explorer "Send To..." - call it "Send To->Webmail Recipient" - what it will do is parcel up the files that have been highlighted and present a (C#) form that will ask for a recipient and then send those files via my webmail system to the recipient.
Can someone point me in the right direction?
-Adrian
|
|
|
|
|
|
I thought so too - however, the article pointed to shows you how to add a "Send To" menu item to your own application, not how to add a menu item to the "Send To" menu.
-Adrian
|
|
|
|
|
I thought there were interesting stuff in the code itself, but anyway. A SendTo handler is a COM object which implements the IDropHandler interface.
Mike dunn has written an article[^] about how to do this using C++/ATL.
Now for C#, the basic start is to implement the IDropHandler interface using the appropriate attributes. A good start is COMInteropPart2\CSharpServer from the VS.NET sample cds. It goes like this :
using System;
using System.Runtime.InteropServices;
namespace CSharpServer
{
[Guid("DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05")]
public interface IManagedInterface
{
int PrintHi(string name);
}
[Guid("C6659361-1625-4746-931C-36014B146679")]
public class InterfaceImplementation : IManagedInterface
{
public int PrintHi(string name)
{
Console.WriteLine("Hello, {0}!", name);
return 33;
}
}
}
|
|
|
|
|
My C# program needs to search all the child and ancestor windows of a known window until it finds one with a particular window name. I guess the only way to do this is to use something like EnumChildWindows and somehow checking each handle to see if the window it points to has the window name I am looking for.
Is there an easier way of doing this in C# without Win32 calls? And if not, how do I setup the callbacks for the call to EnumChildWindows?
|
|
|
|
|
Mattingly wrote:
how do I setup the callbacks for the call to EnumChildWindows?
Just write it as a delegate and pass that into the function. It works in most cases.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Ok, and I guess there is no easier and more .Netish way of finding all the child windows and checking their window names?
|
|
|
|
|
I am trying to decrypt a file using my PGP keyring inside a C# windows console application. I have a program that will detect a new file on my server. I'm building another app that will first decrypt the file and then start the file processing.
The code I use to decrypt the file without inserting a passphrase works but instead uses the passphrase read from password.txt,
gpg.exe --output mydoc.txt --passphrase-fd 0 < password.txt --decrypt myencrypteddoc.dat.pgp
This works when I run it at command line. But inside the console it seems to hang when reading the file descriptor because the command window message "Reading file descriptor 0 ..." continually displays and the decryption never occurs.
Process process = new Process();
process.StartInfo.FileName="E:\\Program Files\\pgp\\gpg.exe";
process.StartInfo.Arguments="--output mydoc.txt --passphrase-fd 0 < password.txt --decrypt myencrypteddoc.dat.pgp";
process.Start();
process.WaitForExit();
Any help with this would be appreciated.
Thank You!
mazn
|
|
|
|
|
Check out the article GPG for .NET here on CP, it's done in dot net and has a wrapper class written in c#.
Besides I'm using a similar one in c++ by creating a pipe and associating it with the standard input handle of the gpg process, whereas eliminating the need to include the passphrase in the commandline.
|
|
|
|
|
Hey peeps,
I have a method like so:
private void RunFunction(string function)
{
.......code here.....
}
I basically want to be able to run a method in the same class from a string containing its name.
i.e.
string = "TheFunction"
this using code, will invoke the method TheFunction()
If there is a way tp pass parameters to the function, that would help too.
i.e. TheFunction(somestring,someint)
Cheers
nonny
"How long has the "Quote Selected Text" been around???" - Marc Clifton, Lounge 4 Mar '03 "But a fresh install - it's like having clean sheets" - Chris Maunder Lounge 3 Mar '03
|
|
|
|
|
Ah, never mind, i've found a way. For those who wanna know its...
public void LoadMethod(string method)
{
Type t = typeof(Class1);
t.InvokeMember(function,BindingFlags.Default |BindingFlags.InvokeMethod,null,this,null,null,null,null);
}
The link to the MSDN page is...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtypeclassinvokemembertopic1.asp[^]
"How long has the "Quote Selected Text" been around???" - Marc Clifton, Lounge 4 Mar '03 "But a fresh install - it's like having clean sheets" - Chris Maunder Lounge 3 Mar '03
|
|
|
|
|
alternatively you could use callbacks also...
|
|
|
|
|
Can't seem to find a way to do this
|
|
|
|
|
Does Application.Exit() not work?
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
|
Nishant S wrote:
Just return from your Main().
Or you could try that
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
do you have thread running ?
|
|
|
|
|
I need to be able to generate short timezone names (like EST, CST etc.). The Timezone class gives me long names but not the short names. Is there any way to get the current short timezone name? I would have thought this would have been in the Timezone object.
Thanks
Kevin
|
|
|
|
|
Hi, all.
I want to paste pictures that have been pasted in Excel.
When I "Copy & Paste" from other tools(MSpaint, MSPhotoEditor etc...),
the format in Clipbord is "Bitmap etc...". So, I can paste it by next code.
Bitmap bmp = (Bitmap)d.GetData(DataFormats.Bitmap)
But, from Excel, the format are "MetafilePict, GIF, PNG, etc... ".
Please help me how to convert(cast) these formats into "Bitmap".
TZN
|
|
|
|
|
i am planning to develop a rule-based ad & popup/-under blocking program as my degree level project. I am planning to use C#. I thinking of having the program as a standalone application that work in the background to screen incoming web pages for ads (by looking for keywords like '/ads' etc), remove the ad displaying codes, then feed it to the browser. the goal here is to prevent ads from being downloaded, so i must intercept the incoming pages before the browser gets to display it. i have no prior knowlege in doing this kind of program. note that the development has not started yet. i am asking this question because i forsee the problems. i have quite a bit of experience in programming.
My problem is: how do i intercept the page, removing the code lines, and then pass it to browser programatically. I am having a technical problem, so i really hope someone can shed some light and lead me to a technical solution.
My program should also distingush the popup/under opened explicitly by the user and the real culprits - the ads. one idea i got from a friend is to scan window's title bar for specific words (like 'great deals' etc) but i know that's not the best way. so again, i hope someone can give me more ideas on how to implement this.
Thanks in advance for all your help.
|
|
|
|
|
That one is a recurrent topic on Cp.
There are two kinds of ad-blockers :
- dictionnary based. They simply enumerate all visible windows on a regular time basis, and then they send a WM_CLOSE message to all windows which happen to have a caption matching an entry in a dictionary of known banned windows. There are two cons about this approach : - you don't prevent ads from being downloaded - the dictionnary needs to be (manually) maintained as there are many many many possible combinations of ad captions while you surf the web. At this point, may be a regexp (buit-in in .NET) can help and avoid the mere listing of banned captions. That's what proxomitron[^] does.
A trivial C# implementation is available here[^].
- the other approach watches URLs as they being requested from web servers. There are several approaches here :
-- hookup Internet Explorer navigation events, especially OnBeforeNavigate2, OnNewWindow2 and OnDocumentComplete.
-- redirect web requests to a proxy filter. This implies the user is required to change his IE settings, which is not that great (euphemism). Your proxy filter listens for connections on a dedicated port, then forwards everything back and forth to the actual web server. In between, he can filter out all html code from ad banners (pattern matching, regexp again). Watch my web condom[^].
-- and finally, you can write a .vxd driver, to monitor all incoming/outgoing requests without requiring users to change anything in their settings. Download the MS DDK. That's hardcore, now you are warned!
In the second approach, depending on how perfectionist you are, you may need an html parser and even a javascript parser, even though from my personal experience I would recommend to stick with regexp and a few exprimental rules (that's were popup unders and stuff like that can be described with simple rules).
|
|
|
|
|
S.Rod,
Thanks for the reply. I'll try to look into the samples u pointed me to. But I am a student, and I am new to this area of developing this kind of program, can u please kindly point me to some other references.. like books i should read etc. i am not familiar with IE hookups as well. can u provide me with more info?
i might not consider the proxy / vxd options to filter the ads...
writing the ad blocker means going into an uncharted territorry for me. i am starting from zero & i need some good pointers and detailed references. your reply marked the start.
thank you.
|
|
|
|
|
.S.Rod. wrote:
This implies the user is required to change his IE settings, which is not that great (euphemism). Your proxy filter listens for connections on a dedicated port, then forwards everything back and forth to the actual web server. In between, he can filter out all html code from ad banners (pattern matching, regexp again).
That makes me wonder if Squid (linux) has a mod like this, especially being able to run as an transparent proxy, no user intervention would be required, except setting the default gateway, great for network use, bad for dialups, but who cares? I run a network anyways.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|