use C# code in vb.net project

G

Guest

I found some C# code on the web that I want to use in my vb.net project.
How can I do this without translating the C# to VB.net?

It's pretty nasty looking or I'd translate it myself
stuff like
#region COM Interop for IShellFolder
[ComImportAttribute()]
[GuidAttribute("000214E6-0000-0000-C000-000000000046")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
//helpstring("IShellFolder interface")
private interface IShellFolder
{
void ParseDisplayName(
IntPtr hwndOwner,
IntPtr pbcReserved,
[MarshalAs(UnmanagedType.LPWStr)] string lpszDisplayName,
out int pchEaten,
out IntPtr ppidl,
out int pdwAttributes);

void EnumObjects(
IntPtr hwndOwner,
[MarshalAs(UnmanagedType.U4)] ESHCONTF grfFlags,
ref IEnumIDList ppenumIDList
);

void BindToObject(
IntPtr pidl,
IntPtr pbcReserved,
ref Guid riid,
ref IShellFolder ppvOut);

thanks


mike w
 
C

Chris, Master of All Things Insignificant

You would have to put it into its own project and compile it as its own dll.
Then reference it from your VB project.

Chris
 
H

Herfried K. Wagner [MVP]

mike w. said:
I found some C# code on the web that I want to use in my vb.net project.
How can I do this without translating the C# to VB.net?

Add a C# project of type "Class Library" to your solution, then insert the
code into the C# project and add a reference to the C# project in your
VB.NET project. It's not possible to mix different programming languages in
a single project.
 
C

Cor Ligthert

And don't than forget in the added C# Project to set the general properties
"output type" to Class Library and do a build for that before you set the
reference in your VB project.

I hope this helps?

Cor

ps. Herfried I had this from an other message half an hour ago.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top