- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHi
For various reasons I need to access a C# class from within a VB project. The C# class calls an API.dll which returns fixed types which are not supported in VB.NET so the idea is to get the C# module to convert these before returning values to VB
So here's the problem - how do I get to access the C# clas in VB.NET the class is
public class API
{
// ¤Þ¥Î Fritz DLL
[DllImport("DllApCli.dll")
public static extern void DebugMsg(int bOn);
[DllImport("DllApCli.dll")
public static extern void ApOpen();
[DllImport("DllApCli.dll")
unsafe public static extern int ApConnectToServer(string szSrvIP, int dwSrvPort);
[DllImport("DllApCli.dll")
unsafe public static extern int ApGetVersion(out int iMajorVer, out int iMinorVer);
[DllImport("DllApCli.dll")
public static extern int ApMessageCount(int hAP);
[DllImport("DllApCli.dll")
public static extern void ApClose();
[DllImport("DllApCli.dll")
public static extern int ApEraseAllMessage(int hAP);
[DllImport("DllApCli.dll")
public static extern void ApDisconnect(int hAP);
[DllImport("DllApCli.dll")
unsafe public static extern int ApGetMessage(int hAP, out long dwUnitID, out int dwMsgID, byte* szBuff, int iBuffLen);
[DllImport("DllApCli.dll")
public static extern int ApAttachCount();
[DllImport("DllApCli.dll")
unsafe public static extern int ApSendCmd(int hAP, long dwUnitID, byte[] szCmd, int iCmdLen);
[DllImport("DllApCli.dll")
unsafe public static extern int GetNumberOfCleint();
}
An example of the ApSendCmd method as called in a C# project is shown below
public void SendMessage(string Message)
{
int IsOK;
byte[] Msg = Encoding.Default.GetBytes(
IsOK = API.ApSendCmd(m_hAP, System.Convert.ToInt32(tvO
switch (IsOK)
{
case 0:
tbConsole.Text += "Send message failed." + "\r\n";
break;
default:
tbConsole.Text += "Send " + Message + " to " + tvOBUGroup.SelectedNode.Te
break;
}
}
How do I replicate this functionality in a VB.Net app?
Many thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: JasonRawlinsPosted on 2008-04-10 at 01:18:37ID: 21322673
Hi,
You can call C# code directly from a VB project if it is in a separate assembly. If you put the interop methods and C# code in a separate class library, then compile it, you can reference that dll from your VB code.