|
hi
befor i get links to threats how i create a string (i think it calls like that in english - german: Zeichenfolge) - no i don't want that!!!
I want to create a reg_expand_sz key in the registry that is another format in the registry.
Thanks for every solution.
i hope you understand what i'm meaning
|
|
|
|
|
If you read the documentation for the RegistryKey.SetValue method, you would find the following:Note When setting a value, the way in which the value being passed is stored in the registry is interpreted. There is no way to control whether the information being passed is stored as an sz, or an expanded_sz string, and therefore, all string values are interpreted as standard sz values.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Like Heath said, it can't be done using the Registry classes in the .NET BCL. You'll have to P/Invoke the calls to the Win32 Registry functions yourself. You can look them up on MSDN here[^] and on pinvoke.net.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need to put pdf document as BackgroundImage in Form. As I see you can put only image files (jpg,bmp,png...) as Form's BackGroundimage. Is there some way to achieve this with pdf?
Boris
|
|
|
|
|
It's possible, but not probable. Unless you expect a dynamic background (what are you trying to do anyway?), just rasterize the PDF as an image (Adobe Acrobat - the full version - can do this) and use that.
To actually display the PDF as a background would require that you be able to read and render PDFs yourself, and that you override OnPaint (when ControlStyles.AllPaintingInWmPaint is set), or OnPaintBackground ) for a form or control and draw it. This would be very intensive, however, so be sure to only draw the PaintEventArgs.ClipRectangle for said form or control. If you redraw the entire PDF each time you'll drag down the system.
How to read and render PDFs? There's many third-party libraries on the market which you can google[^] for, and - because we've talked about this numerous times in this form - you can click "Search comments" for "PDF" to see what others have had to say about certain libraries.
Again, your best bet is to just rasterize the PDF as an image that is supported by GDI+ (which .NET uses) and set that as the background. It's far more efficient and doesn't require that you override any painting, such that Windows itself handles the painting efficiently.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
How would I be able to launch a windows application from a windows service that would display the windows apps interface. I tried starting a process within the windows service to start i.e. notepad.exe but then it is still hidden and the only way you can tell that it is in there is to go to the task manager.
Thanks for the help.
|
|
|
|
|
You either need to run the service as a particular user with interactive login privileges (and then the Windows application will only run in their Windows station), or you need to mark your service as being interactive. This is a manual process, since there is no support currently in the ServiceInstaller or ServiceProcessInstaller , which you use in conjunction with your own Installer class.
A good way to do this is in your override to Installer.Install , use the Registry and RegistryKey classes to open the key for your service, which is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<YourServiceName>, and bitware OR the Type value with 256 (for interactive login). This is only if you run the service as SYSTEM, i.e. setting ServiceProcessInstaller.Username to "" , or String.Empty (which decreases binary size and load times insignificantly).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
thanks a lot. It works
|
|
|
|
|
Hi,
I have a client comopnent (written in C++), which is calling to methods on C# component (using COM Interop).
My problem is, that in some way I need to be able to call from my C# to method implemented in the C++ (kind of a callback...).
Actually it is a kind of "Observer" pattern, where the subscriber is a C++ module and the publisher is a C# component.
for example:
C# Server code:
///
/// The ISink interface is to be implemented by a C++ client
///
interface ISink
{
void OnChange(string msg);
}
interface IServer
{
.
.
int RegistrForChange(ISink sink);
void Broadcast(string msg);
}
class CServer: IServer
{
int IServer.RegisrtForChange(ISing sink)
{
// keep isink in hashtable...
}
int IServer.Broadcast(string msg)
{
foreach (ISink sink in m_hash)
{
sink.OnChange(msg); // OnChange is implemented by the listener (C++)...
}
}
}
C++ Client code
class Client : public ISink //how can this be done...??
{
// Creating IServer object using COM...
void Init()
{
.
.
iServer.RegisterForChange(this);
.
.
}
void OnChange(BSTR msg)
{
printf("Got %s", msg);
}
}
Is there a way of doing this kind of thing???
Thanks!
|
|
|
|
|
What you propose above is a good way of handling such a situation. You simply advise a sink passed to your managed components.
There's several problems, however. When writing CCWs (COM-Callable Wrappers) you need to follow COM best practices. That means attributing your interfaces and coclasses with the GuidAttribute with unique, constant values. Never change an interface definition once published, nor its IID (GuidAttribute value); derive a new interface from it with a different IID and added methods (no overloads, which COM does not support).
So, whether you declare your ISink interface in unmanaged or managed code, make sure you use the same IID.
You might also consider using an interface that is already published for native code: IAdviseSink . This may be more advanced than what you need, however, since it has more to do with clipboard objects (including drag and drop) than anything else.
Also note that while maintaining the same name is a good idea for the interface in both unmanaged and managed code, it's not necessary. So long as the IID and interface definition (including any DispIdAttribute s for IDispatch -derived interfaces) are the same, it's the same interface.
You could also declare events for an interface, which creates a dispinterface for the class if you're declaring the sink in managed code to give to unmanaged code. See the ComSourceInterfaceAttribute for more details.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Stewart, and thank you for replying.
In my real code, I used the GUID, of course...
I wondered if there is a kind of a code snippet (for both the C# and C++) of how to accomplish this task (or a reference where I can find some hints).
Thanks for your reply, again.
|
|
|
|
|
When asking questions in technical forums don't hold anything relevant back if you expect a decent answer. Holding back what you think to be insignificant facts from your doctor could mean life or death. It's similar for forums such as this.
Sample code for what you propose is all over in the Platform SDK for component development (COM docs). It's not different in managed code (except for language symantics). Implement your ISink on your native (unmanaged) class, and pass an instance to a managed method that takes an ISink . Whenever the managed method needs to callback to the sink, it calls the method of the ISink implementation instance. This is quite a simplified form of events in the managed world, which takes a delegate (a managed callback, or handler) and - often times - stores them in a list. When an event occurs the list is enumerated (when applicable) and each delegate is invoked.
As far as specific examples I know of none, but you should easily be able to figure out how to make it work. You just pass your ISink instance to managed code and when an event occurs your managed code calls methods on the sink.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Stewart,
Didn't mean to hold anything relevant back from the doctor...
However, I thought that the concept was clear...
Anyway, I was looking for an example of such implementation or a concrete referecne to some place I can get.
BTW - if I declare an "event" in my C# object - would that be interpreted by the tlb and C++ client as a "Connection Point" interface?
Thanks
|
|
|
|
|
No, you need to specify an interface that defines those events, which is described in the documentation for the ComSourceInterfaceAttribute that I mentioned previously.
For an example of use, see an old article of mine, User Controls for Windows and the Web[^]. In that article I use an event interface so that script (in the web page) can add a handler for an event exposed by my Windows UserControl that is hosted within the web page (like an ActiveX control or Java applet).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Stewart,
I've been playing around today with my code, and got to a point which I could not pass.
My Server code looks like this:
namespace C_Sharp_DLL
{
// The event arguments class
[Serializable]
[Guid("C1BD9A0C-B6D1-4170-A60C-384857C3F84E")]
public class OnChangeEventArgs
{
private string m_msg;
public string Message
{
get {return m_msg;}
set {m_msg = value;}
}
}
public delegate void OnChangeEvent (OnChangeEventArgs onChangeEventArgs);
[Guid("F4A9D17D-6913-4b0a-A635-C5D6F8B1BD62")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
public interface ITestInterface
{
int Test1(string sString);
event OnChangeEvent OnNotifyEvent;
void Notify(string msg);
}
[Guid("0A7F4E0F-59D4-4f59-8DFC-E71F76C96C76")]
[ComSourceInterfaces(typeof(ITestInterface))]
public class Test : ITestInterface
{
public Test()
{
}
int ITestInterface.Test1(string sString)
{
Console.WriteLine("Receive paramter in Test1 : " + sString);
return 1;
}
public event OnChangeEvent OnNotifyEvent;
void ITestInterface.Notify(string msg)
{
OnChangeEventArgs args = new OnChangeEventArgs();
args.Message = msg;
OnNotifyEvent.BeginInvoke(args, null, null);
}
}
}
while my C++ client code looks like:
int main (void)
{
try
{
CoInitialize(NULL);
HRESULT hr;
ITestInterface * pITestInterface = NULL;
hr = CoCreateInstance(CLSID_Test,
NULL,
CLSCTX_ALL,
IID_ITestInterface, reinterpret_cast<void**>(&pITestInterface));
if (FAILED(hr))//REGDB_E_CLASSNOTREG
{
_com_error COMError(hr);
printf (COMError.ErrorMessage());
printf(" Couldn't create the instance!... 0x%x\n", hr);
printf("Failed to create COM Class");
}
else
{
bstr_t s = "1234";
i = pITestInterface->Test1(s);
}
IConnectionPoint * p1 = NULL;
IConnectionPointContainer* pIConnectionPointContainerTemp = NULL;
IUnknown* pIUnknown = NULL;
/*QI this object itself for its IUnknown pointer which will be used */
/*later to connect to the Connection Point of the ISomeInterface object.*/
/* QI pISomeInterface for its connection point.*/
<==this is always succeeds (i.e. not NULL)
pITestInterface -> QueryInterface (IID_IConnectionPointContainer,
(void**)&pIConnectionPointContainerTemp);
if (pIConnectionPointContainerTemp)
{
pIConnectionPointContainerTemp->
FindConnectionPoint(__uuidof(ITestInterface),
&p1); <==this is always returns as NULL
pIConnectionPointContainerTemp -> Release();
pIConnectionPointContainerTemp = NULL;
}
if (p1)
{
//m_pIConnectionPoint -> Advise(pIUnknown, &m_dwEventCookie);
}
//pIUnknown -> Release();
//pIUnknown = NULL;
//
CoUninitialize();
}
catch (_com_error e)
{
printf("%s", e.ErrorMessage());
return 0;
}
catch(...)
{
long lErrorCode;
lErrorCode = GetLastError();
printf("Fatal error");
return 0;
}
return 1;
}
Can you try and point me where can the problem possibly be?
Why does FindConnectionPoint always fail while
pITestInterface -> QueryInterface (IID_IConnectionPointContainer,
(void**)&pIConnectionPointContainerTemp);
succeeds?
Thnks...
|
|
|
|
|
You don't actually implement the event source. Read Raising Events Handled by a COM Sink[^], and pay close attention to "Handling and Raising Events" which discusses events for managed code. I mention that last part only because your event naming convention isn't "correct". Being consistent is important. Besides, events in COM should begin with "On", and you'll almost never see this (except for MSHTML, but only because of the way it works with script). To handle that event in VB (6 and below), you'd have a handler called "OnOnNotifyEvent". You also shouldn't end the event name with "Event".
The guidelines are quite clear on this and are similar to what's recommended and common for COM, as well (since .NET is a natural progression of COM). Read the Naming Guidelines[^] for more information.
The times you will see "On" in COM is when you're not dealing with connection points, but with sinks like I mentioned before, which you were leaning to originally. In that case you're not actually sinking a connection point but calling a method on the sink. It's similar in nature, but you handle the sink a little differently than a connection point (the overall behavior is the same, however).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
So I'm trying to access MS-Word's spell checker. However I won't know which version of word is install on the clients computer. So I'm using late binding to access the com interface.
So far I have been able to create a document. Get a reference to the application and call the GetSpellingSuggestions.
After calling GetSpellingSuggestions with "noow", I see that the count for the SpellingSuggestions is 4, which is correct.
My question is how do I access the SpellingSuggestions collection.
Using a BindingFlags.GetProperty I get a "'Item' is not a property"
Using a BindingFlags.InvokeMethod and passing the index as an argument, I get "Invalid number of parameters."
Any help would be greatly appreciated.
Here is the code I'm using.
<br />
using System;<br />
using System.Reflection;<br />
using System.Collections;<br />
<br />
namespace spellcs<br />
{<br />
class Class1<br />
{<br />
public static void Main()<br />
{<br />
object M = Type.Missing;<br />
object obj = null;<br />
<br />
Type oType = Type.GetTypeFromProgID("Word.Document");<br />
if(oType != null)<br />
{<br />
obj = Activator.CreateInstance(oType);<br />
}<br />
<br />
Console.WriteLine(obj.GetType().ToString());<br />
<br />
object[] args = new object[12];<br />
args[0] = M;<br />
args[1] = true;<br />
args[2] = true;<br />
args[3] = M;<br />
args[4] = M;<br />
args[5] = M;<br />
args[6] = M;<br />
args[7] = M;<br />
args[8] = M;<br />
args[9] = M;<br />
args[10] = M;<br />
args[11] = M;<br />
<br />
oType.InvokeMember("CheckSpelling",BindingFlags.InvokeMethod, null, obj, args);<br />
<br />
object oApp = oType.InvokeMember("Application", BindingFlags.GetProperty,null, obj,null);<br />
<br />
Type tApp = oApp.GetType();<br />
<br />
object list= null;<br />
object Count = null;<br />
try<br />
{<br />
<br />
list = tApp.InvokeMember("GetSpellingSuggestions",BindingFlags.InvokeMethod,null, oApp, new object[]{"noow", M, true, M, M, M, M, M, M, M, M, M, M});<br />
Count = list.GetType().InvokeMember("Count", BindingFlags.GetProperty, null, list, null);<br />
<br />
<br />
Console.WriteLine(Count);<br />
for(int i = 0; i < (int)Count ; i++)<br />
{<br />
object[] args2 = new object[] {0,0};<br />
<br />
object word = list.GetType().InvokeMember("Item",BindingFlags.Default | BindingFlags.InvokeMethod | BindingFlags.Instance, null, list, null);<br />
Console.WriteLine(word.ToString());<br />
}<br />
<br />
}<br />
catch(Exception e)<br />
{<br />
Console.WriteLine(e.Message);<br />
if(e.InnerException!=null)<br />
Console.WriteLine(e.InnerException.Message);<br />
<br />
Console.WriteLine(e.GetType().ToString());<br />
}<br />
<br />
Console.ReadLine();<br />
<br />
tApp.InvokeMember("Quit",BindingFlags.InvokeMethod,null, oApp,new object[]{0,0,false});<br />
}<br />
}<br />
}<br />
|
|
|
|
|
The fact that you're using a COM interop assembly generated from a typelib already means your accessing Word through it's IDispatch pointers, i.e. you're already late-binding to Word.
If you want to automate Word and its tools in such a manner, create an interop library (using tlbimp.exe or creating a managed reference from the COM tab for your project) from the oldest typelib you want to support. You can also use a newer typelib but this could lead to problems if you use any newer interfaces.
This is how COM is supposed to work when implemented correctly, and Office is a shining example of COM best practices. So long as you never changed published interfaces or the CLSIDs of classes, automation clients will continue to work for newer automation servers.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Now that makes sense. I was developing on my laptop with that has office 2003 and then trying it on a machine with office 2000. For some reason I thought to use the interop would require finding a way to determine with one to use lib to use at runtime.
Thanks for the info. I'll try it out.
Darren
|
|
|
|
|
Heath...
That worked perfectly. I'm using a typelib from word 2000 and it also works with XP and 2003.
Thanks again.
Darren
|
|
|
|
|
Hi
how i can send an email from my computer to an email address on yahoo ??? or any where?
it means that i dont know some parameters of SMTP ' QuickSend method like
"SMTPServerName".
thanks.
|
|
|
|
|
For the uninformed, QuickSend and SMTPServerName are both API calls in Quiksoft STMP email API for .NET.
WDI, e-mails are sent using an SMTP mail server. If you're running Windows XP Pro, a mail server is built into the machine. Typically, the address of an SMTP server is something like smtp.provider.com -- you can use your XP Pro machine to be the mail server for you, or use an existing mail service, or one provided by your ISP; either case you need to get the smtp mail address for the mail service you want to use for sending your email.
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
A CDO client is included with Win2K and above, and you can install the Virtual SMTP Service for IIS in Pro/eHome, but it is not there by default. It can be added easily enough through Add/Remove Programs, but many people have trouble configuring it especially when it comes to forwarding to an outgoing SMTP host that accepts forward from their "domain".
SMTP connections can often be - except when blocked by firewalls - made from your local machine directly, rather than forwarding to another SMTP host. To the original poster, if you click "Search comments" and search for "SMTP" you can find many messages related to sending emails yourself.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi
I've written my own VNC Client using classes from cdot.senecac.on.ca/projects/vncsharp/
It works fine!
But I got one Problem!
I need a solution to expand the Contxt Menu that opens when you click
right on the Title bar from the Windows Form. It shows only 'Close',
'Minimize' etc.. It's the same Dialog when a Form is minimized to the Task bar.
In the Form Propertys I found no answer. Where is it anchored?
Thx from Germany!!
|
|
|
|
|
|