How to access functions in a .lib file in vb.net 2008

gloier
gloier used Ask the Experts™
on
How to link a .lib file to a visual basic program, vb.net 2008, so I have access to the functions in the .lib file
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:

A .lib is a staticly linked file (something that is included in the executable). dotNET thrives on dll's instead of libs, so you will have to build a wrapper for it.

http://geeklit.blogspot.com/2006/08/calling-c-lib-from-c.html is a blog-entry about calling a .lib from c# where he compiles the .lib into a .dll-file. That should give you a start.
fridomCEO/Programmer

Commented:
Well there are two kinds of .lib files the ones dijaries has mentioned, but also the so called import libraries. I assume very much that this is such a import library. You can check if there is another file with the same name but with .dll as ending. Then you can be relativly sure that this is a import library. You can than access this library with the "usual" PInvoke facilities.

Regards
Friedrich

Author

Commented:

Yes , I have another file with the same name with .dll extension.
Kindly explain the how to access  this library with usual Pinvoke.

Regards
Gloier
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

fridomCEO/Programmer

Commented:
http://msdn.microsoft.com/en-us/magazine/cc164123.aspx

Here's a very primitive example

There is one really thick companion which covers all this Interoperability Stuff.
.NET and COM, from Nathan....

C Code: 
#include "TestInvokeSharedLib.h"


int DLL_FLAG anAdderFunction(int a, int b) {
	int result;
	result = a + b;
	return result;
}

and this is the C# code which calls into the above generated DLL and does call this function: 
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;



namespace UsingPinvoke
{
    class Program
    {
        [DllImport("TestPinvokeSharedLib.dll")]
        public static extern int anAdderFunction(int a, int b);

        static void Main(string[] args)
        {
              int result;
            result = anAdderFunction(10,20);
            Console.WriteLine ("result = " + result);
        }
    }
}

Output:
result = 30
Drücken Sie eine beliebige Taste . . .

Open in new window

fridomCEO/Programmer

Commented:
Just so much.
1) ist wasn't a static library ( I pointed out how to figure that out)
2) I wrote about the PInvoke facilities
3) I provided an example on how to use it.

I'd think that is more than enouugh for at least some assist points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial