|
Hi,
can anyone help me converting vb.net code given below into c#. also, if i have .dll project, how do i convert the .dll executable at the same time.. i appreciate ur help. Thanks...
vb.net code
-------------
Private Function GetSingleProperty(ByRef sElementName As String) As String
Dim vValues As Object
vValues = g_pPropSet.GetProperty(sElementName)
If IsNothing(vValues) Then
GetSingleProperty = ""
ElseIf VarType(vValues(LBound(vValues))) <> VariantType.String Then
GetSingleProperty = ""
Else
GetSingleProperty = vValues(LBound(vValues))
End If
End Function
vijju
|
|
|
|
|
Why bother? Are you forgetting that all managed languages compile down to Intermediate Language? The source language doesn't matter; the associated compilers compiles that to IL and assemblies it in a module, which then gets embedded into an assembly along with embedded resources (if any). So why bother redoing it in C#? Just have your C# project reference the VB.NET assembly and viola'! The BCL (base class library) assemblies are written in C#, but you can use them in VB.NET, MC++, J#, and all the other languages, can't you?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Help! Help! Help!
I have a usercontrol that have a collection contain of a class(or struct). I want the collection be save autamatically with form's code.
my code:
public class Struct1<br />
{<br />
private int m_x ;<br />
public int x <br />
{<br />
get{return m_x;}<br />
set{m_x=value;}<br />
}<br />
private string m_y ;<br />
public string y <br />
{<br />
get{return m_y;}<br />
set{m_y=value;}<br />
}<br />
}<br />
private Struct1 m_struct ;<br />
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]<br />
<br />
public Struct1 STRUCT<br />
{<br />
get{return m_struct ;}<br />
set{m_struct=value;}<br />
}<br />
<br />
public class MyCoulumnClollectionClass : CollectionBase<br />
{<br />
<br />
public Struct1 this[ int index ] <br />
{<br />
get <br />
{<br />
return( (Struct1) List[index] );<br />
}<br />
set <br />
{<br />
List[index] = value;<br />
}<br />
}<br />
public int Add( Struct1 value ) <br />
{<br />
return( List.Add( value ) );<br />
}<br />
<br />
public int IndexOf( Struct1 value ) <br />
{<br />
return( List.IndexOf( value ) );<br />
}<br />
<br />
public void Insert( int index, Struct1 value ) <br />
{<br />
List.Insert( index, value );<br />
}<br />
<br />
public void Remove( Struct1 value ) <br />
{<br />
List.Remove( value );<br />
}<br />
<br />
public bool Contains( Struct1 value ) <br />
{<br />
return( List.Contains( value ) );<br />
}<br />
}
|
|
|
|
|
How many more times must I say, that if the DesignerSerializationVisibilityAttribute isn't giving you the effect you want, you will have to derive your own CodeDomSerializer and reference your implementation in the DesignerSerializerAttribute that would attribute your collection property? Those are your only two options, the the one option obviously doesn't work. Do the math.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi.
Thank you.
But i try to using CodeDomSerializer , but it is failed.
|
|
|
|
|
Then you're doing something wrong, because it works for many classes in the BCL as well as many other third-party controls I've used that must use a CodeDomSerializer . But since you didn't say why it failed (exceptions, problems, don't know what you're doing, whatever), I can't really help you.
Learn to be specific when asking for help, because saying things like "it failed" doesn't help at all.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I create a group of radio buttons so the user can select the database they want.
When the user clicks one of the buttons, the event issues a detatch and re-attach to the proper database.
The problem I am having is that during the form load I read the registry to find the current selection and then set the radio buttons showing which one has been checked by issuing a xyz.Checked = true;
This then forces a click event which causes the db to detach/reattach.
I only want the db to detach/reattach when the radio button is cliked by the user not during load.
I get the same stuff using the CheckedChanged event and setting a bool first time pass doesn't seem to do the trick either.
Thanks,
Craig
|
|
|
|
|
The obvious solution is to use a state variable. While loading, this variable could be unset. Once the form is done loading (say, in the OnLoad override in your Form ), set this variable. In your client event handler, determine if the variable is set. Only then do you execute your code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have developed a Windows service application running on my machine. I was trying to implement a screen capture utility for it. I have a working (at least in clasic Windows form application) screen capture class.
But when I try to capture screen from my service it saves a file and the content is all black.
Did anyone try to capture screen from Windows service application and manage to get it work? Any ideas?
Thank you. Milos.
"some people never go crazy
oh how trully horrible life they've lived" -- Charles Bukowski
|
|
|
|
|
The service has to be enabled for interaction with the desktop. After you install the service using the ServiceProcessInstaller and ServiceInstaller , go to your services control panel, double-click on the service to show its properties, then click the security tab. Select "Allow service to interact with desktop". If you don't, the service does not get it's own window station and the screen would be black (frankly, I'm surprised it work at all, meaning you must have caught an exception somewhere and continued drawing a background or something).
You could also enable this during installation, but you'll have to do so manually. In your own Installer class, override OnCommitting and use the registry classes in the Microsoft.Win32 namespace to change the registry key accordingly (bitwise OR the Type key under the service key - using the service name, not the display name - with 256, IIRC).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm trying to use PropertyGrid to set the props of a remote object. At first it looked ok, but then I complicated it by adding plugins. So now I got the following class tree:
Node : MarshalByRef
Handler : Node
[plugin] : Handler
The plugin object is instansiated by sending the class name to the server, who looks it up in the assebly, creates it and returns it.
// client call
private void NewHandler(object sender, EventArgs e)
{
MenuItem mi = sender as MenuItem;
Handler node = server.CreateHandler(mi.Text);
handlersNode.Nodes.Add(new NodeFacet(node));
propertyGrid1.SelectedObject = node;
// node.NodeChanged += new NodeChange(NodeChanged);
}
// server side
public Handler CreateHandler(string type)
{
Handler node = this.CreateNode(type, handlerTypes) as Handler;
Handlers.Add(node);
return node;
}
In debugger I can see that the node is of the correct subclass, but on the client side I only get the properties from my Handler and Node class.
Any suggestion?
|
|
|
|
|
Hi gurus,
Where can I find a C# sample code that shows how to send a class with DirectPlay? I can send text but I need to send binary data.
best regards.
There is no spoon.
|
|
|
|
|
Have you looked in the DirectX SDK documentation for Managed Languages? All you need is either a NetworkPacket or a GCHandle (which you can create using any type). To use a NetworkPacket , all you have to do is pass a ValueType , which is any primative, enum, or struct (they all derive from ValueType ).
So, to use a NetworkPackget :
using (NetworkPacket pkt = new NetworkPacket())
{
pkt.Write(new Point(8, 8));
client.Send(pkt, 0, SendFlags.Guaranteed);
} If you're looking for a good resource on Managed DirectX, I highly recommend Managed DirectX 9 Kick Start: Graphics and Game Programming[^]. It's a good read and includes several chapters on DirectPlay. Honestly, though, it's not too tuff, especially after reading that book. It's certainly a lot easier than many .NET Remoting applications I've designed and help write!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ah ok...
We can't send a complete class, but we can send simply a structure derived from ValueType...
in a class that handle DirectPlay, is it necessary to use trnasactions with
[Transaction(TransactionOption.Required)] ?
Or the flag SendFlags.Guaranteed is enough?
NB: thanks for the link, but the MSDN is largely enough. I just messed up with the parameters... they need to be a structure, not a class :P
There is no spoon.
|
|
|
|
|
The TransactionAttribute is for service components (i.e., COM+ services), not DirectPlay (or any DirectX). They have nothing to do with each other. You can't just mix and match APIs.
If you want to send a class, use the Client.Send overload that requires a GCHandle , as I mentioned before. Most importantly, read the docs. I know the DirectX SDK documentation sucks (NDoc[^] is free and does a better job), but at least you can see what classes and members are available; that's all I did to answer your question (since I knew the basics already).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have created a structure with basic data (bool & int) and the structure is not sent. there is an exception that tells "An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Object contains non-primitive or non-blittable data."
while the strcuture looks like this:
public struct TetrionParams
{
#region Fields
public bool DrawGrid;
public bool Draw3D;
public bool ShowGhostPolymino;
public bool ShowNextPolymino;
public int Width, Height;
#endregion
}
There is no spoon.
|
|
|
|
|
How are you calling Client.Send with this struct? More information is required to help you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
that's okay, I've found a sample in the tutorials of DirectX that shows how to send binary data.
the data need to be transfered byte by byte in the NetworkPacket. the Tut10_ThreadPool tutorial in the ThreadPool.SendData() method.
There is no spoon.
|
|
|
|
|
Hi ..
I'm writting a video player in C# using DirectShow ..
I would like to play Quicktime movies and VR too .. i found the Interop.QTActiveXPlugin.dll .. but i have not been able to play a single movie ..
I hope some one can help me get a Quicktime movie to play in C# without using an embeded HTML page containing a Quicktime <object> ..
Thanx ..
|
|
|
|
|
buffer_k.st wrote:
i found the Interop.QTActiveXPlugin.dll .. but i have not been able to play a single movie ..
For one, you must have QuickTime installed on your machine. An interop assembly is an RCW (Runtime Callable Wrapper) that exposes an existing COM server to .NET. The QuickTime ActiveX control is installed on Windows when you install QuickTime. Second, you can make your own. By saying you "found" the interop assembly - do you trust the source? All you have to do to make one is, in VS.NET, right-click on your project, select Add Reference, click on the COM tab, and find the QuickTime library. Double-click to add it. This create an interop assembly.
However, you must also create an ActiveX wrapper. Do this by right-clicking on your toolbox and selecting "Customize" (it's a little different for different versions of VS.NET, but common sense should tell you want to click). Find the ActiveX control for QuickTime and double-click to add it. When you drag this to your form or user control, both the ActiveX interop assembly and the interop assembly you created above (if you haven't yet) are created automatically for you. It's this ActiveX control (AxHost derivative) that you use to display videos.
You cannot use DirectShow to play newer (like, within the last few years) QT files because they do not use a compatible codec (on purpose), just as RealNetworks doesn't.
Finally, if you're having a problem, please be specific. Saying something like "but i have not been able to play a single movie .." doesn't help. Are you getting any exceptions? Do you just not know what to do?
The last question shouldn't be a problem, though. Follow the instructions above, or search for existing articles. It's really quite easy.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok to be more specific ..
Quicktime was already installed .. i found the quicktime COM "QTPlugin.ocx" wich contain Interop.QTPlugin.dll .. but i can't find the axInterop (ActiveX) dll file ..
I downloaded the Quicktime 6 SDK but it is for JAVA and C++ .. I've been searching all over to find the quicktime ActiveX .. but can't find it .. please help ..
|
|
|
|
|
As I mentioned previously, you must customize your toolbox (where all the controls are) and add the QuickTime ActiveX control in there. In fact, forget the step of creating an interop assembly manually - that only defines the types exported from a COM typelib.
When you drag that QuickTime ActiveX control from the toolbox to your form, VS.NET automatically creates the "AxInterop" and "Interop" assemblies. Before doing this, however - if you plan on deploying your application outside of your control, right-click on your project in VS.NET and find the AssemblyKeyFile and AssemblyKeyName properties (something like that). If you want to generate a strong name assembly - even for the interop assemblies (in order to install into the GAC or for purposes of assembly binding redirection) - type the project-relative or absolute path to your key pair file, or type the name of the key container that contains your key pair.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I did what u said .. and it works perfectly ..
Thank you very much for helping me out .. I didn't realize it was that simple and that powerful ..
|
|
|
|
|
Hi Everybody!
I have a question concerning outlook add-ins written in c#. I'd like to write such an add-in but just can't get this thing to work. The main problem is that I don't own a vs.net license, but use SharpDevelop. I used VS.net's wizard at university to create a short plugin template and filled it with some code I found in an MSDN blog article (http://blogs.msdn.com/dancre/archive/2004/03/21/93712.aspx).
But whatever I am trying, I just can't get this thing to work. At home I installed the office XP PIAs and referenced them from the project. I had a look at the installation project from the VS.net solution and added the same registry keys:
<br />
Windows Registry Editor Version 5.00<br />
<br />
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Outlook\Addins\SharpPrivacyOutlook.Connect]<br />
"LoadBehavior"=dword:00000003<br />
"Description"="Outlook Add-in for OpenPGP Encryption"<br />
"FriendlyName"="SharpPrivacy Outlook"<br />
However even though the project compiles all right in sharpdevelop, it doesn't get loaded by outlook. If i try to install it manually (in Outlook - Extras - Options - Extended Options - COM Add-Ins [roughly translated from the German Outlook version]), I get the error message: "SharpPrivacyOutlook.dll is not a valid office add-in".
Is there anything else I need to do to install the add-in? Just in case someone wants to have a look at the code or the dll, I put a copy on the project webserver.
I'm glad for any kind of help!
Thanks in advance,
Daniel
---
SharpPrivacy - A free OpenPGP Implementation in c#
http://sharpprivacy.sf.net
|
|
|
|
|
It's not a valid COM add-in, and whether you use SharpDevelop, VS.NET, or command-line tools it doesn't matter.
A .NET assembly only has the same extensions as native executables, and resembles a PE/COFF executable up until the load address and data segments. It's actually more akin to a VB6 DLL. It doesn't contain the same entry points as a native COM DLL, so a shim is required.
You must actually register your .NET DLL using regasm.exe, after installing it into the Global Assembly Cache (GAC) using gacutil.exe; otherwise, specify regasm.exe /codebase when installing to register the path to the assembly.
This registers your .NET assembly as a COM DLL, but the actual InprocServer is mscoree.dll, the managed executable loader. It is the GUID under which your .NET assembly is registers that you should store in the Outlook options registry key. It will actually load mscoree.dll, which will marshal calls to and from your .NET assembly to Outlook.
There are articles about this on MSDN as well, though they talk about creating your own shim (which is stupid, since mscoree.dll that ships with the .NET Framework must exist and is already a shim!).
To make your .NET assembly a decent COM-visible assembly, you should follow several guidelines (like all COM should):- Attribute your assembly with a
GuidAttribute (like [assembly: Guid("01234567-0123-0123-0123-012345678901")]</coode>)<li>Attribute all classes and interfaces with unique <code>GuidAttribute s as well - Never use auto-generated class interfaces; always specify
ClassInterfaceType.None and explicitly define your interfaces and implement the class interface as the first interface - Never change your release interface declarations; always create new interfaces that inherit from them and implement those as the new class interfaces. Use a new
GuidAttribute as well, but don't remove the previous interface and make sure it's still implemented properly
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|