|
Why this code freeze the application ?
Best wishes and happy new year.
//////////////////////////////////////////////////////////////////////////////////
using System.Runtime.InteropServices;
public class...
{
[DllImport("wininet.dll")]
public static extern bool InternetGetConnectedState(int lpdwFlags, int dwReserved);
...
bool res;
res = InternetGetConnectedState(0, 0);
switch (res)
{
case true:
MessageBox.Show("Connecté");
break;
case false:
MessageBox.Show("Non connecté");
break;
}
}
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
That should be:
[DllImport("wininet.dll")]
public static extern bool InternetGetConnectedState(
out int lpdwFlags, int dwReserved);
...
int flags;
bool ret = InternetGetConnectedState(out flags, 0);
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Im still confused and going round in circles with this stuff. Bear with me as I explain what I have done and am doing.
What I am attempting to do is write a "quick and dirty" MAPI Service Provider to implement a mail sender that posts via an XML interface over HTTP. The XML interface over HTTP bit is working already.
Now, my thought was "Well, .NET does XML nicely so I don't have to get dirty with that stuff", and so I decided to learn what was involved in writing a service provider.
Step 1: Read all about it
- In this case, this meant digging up a copy of "Inside MAPI", which is apparently the only book on writing service providers. I tried going through the MSDN collection, but - quite frankly - in this area, it sucks (altho I did come across an article saying "MAPI isn't dead yet", which is heartening).
Now, in reading, I learnt that I needed to do the following:
- Code a Windows DLL with implements ServiceEntry() and XPProviderInit() and three COM interfaces (IXPProvider, IXPLogon and IMAPIStatus, all of which seem to inherit IUnknown).
I figured here that ServiceEntry() and XPProviderInit() will have to be in some class - probably the "default" class, if such a beast exists - since these will kick off Windows Forms for configuration dialogs, this shouldn't really be the stumbling block.
So I decided my first task was coding the .NET replacements for IXPLogon, IXPProvider, and IMAPIStatus. This is where I get confused, and Microsofts reference turns me round and round in a circular mess until I am confused.
Thus far, I get to the following code, which I think is right
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace MAPI.Extended<br />
{<br />
[Guid("insert-my-generated-guid-here")]<br />
interface IXPLogon<br />
{<br />
void Shutdown(UInt32 lpulFlags);<br />
<br />
}<br />
}<br />
Now, this last one has me more than a little concerned, but I figure that if I can work this one out, then I am in good shape for the other ones. The MSDN documentation says ULONG becomes a UInt32, LPTSTR becomes a String - this is fairly easy.
LPMAPISUP is a pointer to an object which implements IMAPISupport. Thus, I figure I can replace that with IMAPISupport lpMAPISup possibly? LPXPLOGON is a similar (IXPLogon) object, so I figure I can replace that with IXPLogon lppXPLogon... or do I need to replace these with something else because they are pointers? (Im confused).
How about ULONG FAR *? I know ULONG => UInt32, but what about a pointer? Do I do a ref? That MAPIERROR is a pointer to an enum (I think), so I define the MAPIERROR enum and reference it here?
In other words, here is what I *think* it should look like:
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace MAPI.Extended<br />
{<br />
[Guid("insert-my-generated-guid-here")]<br />
interface IXPLogon<br />
{<br />
void Shutdown(<br />
ref UInt32 lpulFlags);<br />
<br />
void TransportLogon(<br />
IMAPISupport lpMAPISup,<br />
UInt32 ulUIParam,<br />
string lpszProfileName,<br />
ref UInt32 lpulFlags,<br />
ref MAPIERROR lppMAPIError,<br />
ref IXPLogon lppXPLogon);<br />
}<br />
}<br />
How close am I?
|
|
|
|
|
Hi all,
I've been working on a problem for the last while and I think I'm after backing myself into a nasty corner. Anyway, is it possible to serialize and de-serialize an ArrayList object?
Thanks for yeer help.
Johnny
|
|
|
|
|
worked fine for me... and its marked [serializable] in the help docs....
Some ideas are so stupid that only an intellectual could have thought of them - George Orwell
|
|
|
|
|
I've been working on getting the CreateProcessWithLogonW System call to work, and have been having trouble. What I have now always generates a Windows error #87 (Invalid Parameter). Can anyone help? This is the relevant code:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
private struct STARTUPINFO
{
public int cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public int dwX;
public int dwY;
public int dwXSize;
public int dwYSize;
public int dwXCountChars;
public int dwYCountChars;
public int dwFillAttribute;
public int dwFlags;
public int wShowWindow;
public int cbReserved2;
public int lpReserved2;
public int hStdInput;
public int hStdOutput;
public int hStdError;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
private struct PROCESS_INFORMATION
{
public int hProcess;
public int hThread;
public int dwProcessId;
public int dwThreadId;
}
[DllImport("advapi32.dll", CharSet=CharSet.Unicode)]
private static extern bool CreateProcessWithLogonW(
String lpUsername,
String lpDomain,
String lpPassword,
int dwLogonFlags,
String lpApplicationName,
String lpCommandLine,
int dwCreationFlags,
IntPtr lpEnvironment,
String lpCurrentDirectory,
STARTUPINFO lpStartupInfo,
PROCESS_INFORMATION lpProcessInfo);
...
bool b = CreateProcessWithLogonW(UserName, Domain, Password, 1, "c:\\winnt\\system32\\cmd.exe, null, 1, (IntPtr)null, null, si, pi);
|
|
|
|
|
Two things I can see might help:
1. You probably need to initialize the cb member of your STARTUPINFO structure to sizeof(STARTUPINFO). Not that this is considered "unsafe". Not bad, you just need to enclose the statement in an unsafe block.
Declare the STARTUPINFO and PROCESS_INFORMATION arguments as "ref". You'll also need to put the word ref in the argument list when you call it.
|
|
|
|
|
OK, I've changed the code so it looks like this now:
[DllImport("advapi32.dll", CharSet=CharSet.Unicode)]
private static extern bool CreateProcessWithLogonW(
String lpUsername,
String lpDomain,
String lpPassword,
int dwLogonFlags,
String lpApplicationName,
String lpCommandLine,
int dwCreationFlags,
IntPtr lpEnvironment,
String lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
ref PROCESS_INFORMATION lpProcessInfo);
int size = si.cb = Marshal.SizeOf(typeof(STARTUPINFO));
bool b = CreateProcessWithLogonW(UserName, Domain, Password, 1, Application, null, 1, (IntPtr)null, null, ref si, ref pi);
It's still failing with error #87...any other ideas?
|
|
|
|
|
I hope this is an easy question:
How do i find the screen resolution in .NET?
I want to make sure that if the resolution was reduced, my program won't come up out of the visible range.
Thanks,
Steve
|
|
|
|
|
you can get the rectangle that defines the desktop boundaries with
Rectangle DTRect = Screen.GetBounds();
To get the working area (destop minus taskbar and docked windows):
Screen.GetWorkingArea(Screen.GetBounds());
Some ideas are so stupid that only an intellectual could have thought of them - George Orwell
|
|
|
|
|
Thanks. I knew it would be something obvious like "Screen". I kept trying to find a "Display" object.
-Steve
|
|
|
|
|
I'll try to keep this short
I am working on an app for which I would like the user interface to be customizeable. Not just in appearance (control location) but in terms of content as well.
I am considering have a series of DATA tables in the database that contain the content" for the application, and a METADATA table that contains a mapping for DATA fields, and form controls (including screen position, labeling, etc). The mapping capabilities will need to be 2-way, meaning a screen scrape-> persist as well as read from db -> display.
(For performance reasons, I am thinking that creating an in-memory cache of "rendered" forms for the different DATA types would be usefull. Not sure exactly how to handle this.)
Has anyone else tried something similar? Does anyone see any major "landmines" that I am about to step on?
Mike Stanbrook
mstanbrook@yahoo.com
|
|
|
|
|
Paul DiLascia made something about it, here[^]. Open Xml GUI framework.
|
|
|
|
|
THIS IS URGENT PLEASE, I POSTED EARLIER BUT NO REPLY.
I'm using the following code to send an output string to a printer but I need the printer to write it from Right to Left instead of Left to Right because otherwise it will be impossible to adjust specially with long text...
PrintFont = new Font("Tahoma", 10);
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = pd.PrinterSettings.PaperSizes[(int)myRegistry.GetValue("Paper Size")];
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
Jassim
Jassim Rahma
|
|
|
|
|
I am packaging my application for distribution. One of the items I have on the To-do list is to put a shortcut in the Start menu with a particular icon.
I started an Installer project, right clicked on the project and chose View->File System. I selected the "User's Programs Menu" and created a folder. I then created a shortcut from my Application Folder/Primary output from ... and placed it in this folder.
Now comes the bit which doesn't work. I right clicked on the shortcut I had created, and selected Properties Window. This has an "Icon" item. I want to change the Icon so that it looks like my program. So I browse and select the App icon inside my Primary output file.
Build/install and I get the default icon look - not my custom icon.
Hmmm - I thought - why don't I add a .ico file with the appropriate icon in it, and point the icon at that. So I uninstall the previous version, alter the icon, build/install and I get the same default icon look.
Can someone please explain how I can make my installed shortcut have my desired icon?
-Adrian
|
|
|
|
|
I did almost the same as you, but instead of pointing at the .ico file in the project or a custom one I pointed at the .exe I was creating the shortcut to then chose the icon I wanted from the list.
That did the trick for me anyway.
James
"The elastic retreat rings the close of play as the last wave uncovers
the newfangled way.
But your new shoes are worn at the heels and
your suntan does rapidly peel and
your wise men don't know how it feels to be thick as a brick."
"Thick as a Brick" from Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Yep - thats what I did the first time (the application Icon App.ico which is embedded into the executable) - that didn't work for me.
Alternative - are there any alternate setup/installer systems out there that integrate with VS.NET IDE?
-Adrian
|
|
|
|
|
InstallShield is there but I its a differnt beast altogether, but has all the facilities you need to prepare a good installer but has a good learning curve.
Kannan
|
|
|
|
|
I want to implement the IObjectWithSite interface (and
others too, this is just a concrete example).
Did Microsoft already implemented these interfaces? I
saw that in some beta they reside in
Microsoft.Win32.Interop or something. Now it is gone.
Do I have to manually do that, use a tool, or they are
implemented somewhere?
Please help!
|
|
|
|
|
Hate to tell you this, but it's not there at all. Looks like you'll have to write it yourself.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
IObjectWithSite is just a stupid interface with only 2 methods aimed to register yourself as a host.
You've got samples for that in many places (even in codeproject). Here are some :
- ATL : IObjectWithSiteImpl default implementation
- IE samples : bandobj, explorerbar, regview, ...
|
|
|
|
|
This particular one is really simple.
But what about IDownloadManager. It has a lot of things to implement.
There should be some namespace, some tool, or some third-party stuff about that. Right?
|
|
|
|
|
standard Workflow, here[^].
A working sample[^] (written in Delphi, but easy to understand).
|
|
|
|
|
I know about these.
Here the problem is much bigger, you have numbers of interfaces to implement to make it working.
Isn't there any tool for implementing them automatically?
|
|
|
|
|
Rincewind wrote:
Here the problem is much bigger, you have numbers of interfaces to implement to make it working.
You have been talking about the download manager, which is a simple callback mechanism. Other interfaces, such as IObjectWithSite, are interfaces that of course have to be implemented since you are building a IE host, but that's a total different story than the download manager stuff itself.
As you have probably seen from the samples I have referred to, there is a way to simplify your life as a coder by just querying the IServiceProvider services, instead of building a full fledge host. You decide.
Rincewind wrote:
any tool for implementing them automatically?
And yes, ATL provides some default implementation for a lot of these standard ActiveX interfaces.
Codeproject is often the automatical implementation for your needs.
|
|
|
|
|