473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calling VB 6.0 Function from C# .Net

Hello All,
I am having vb 6.0 ActiveX dll contains one method
Expand|Select|Wrap|Line Numbers
  1. Public Function GetHandleCount() As String
  2. Set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
  3. Set objServicesCimv2 = GetObject("winmgmts:\\" _
  4.     & "." & "\root\cimv2")
  5. Set objRefreshableItem = objRefresher.AddEnum(objServicesCimv2, "Win32_PerfFormattedData_PerfProc_Process")
  6. objRefresher.Refresh
  7. strf = Format(Now, "dd-MMM-yyyy HH:nn:ss") & "." & Right(Format(Timer, "#0.000"), 3)
  8.   For I = 1 To 2
  9.  objRefresher.Refresh
  10.     For Each Process In objRefreshableItem.ObjectSet
  11.  
  12.         If Process.Name = "_Total" Then
  13.           strf = strf & "  " & Process.HandleCount
  14.       End If
  15.     Next
  16. Next
  17.  GetHandleCount = strf
  18. End Function
  19.  
In C#.Net console application i added this vb 6.0 dll and crated the object to that and then try to access GetHandleCount() method.
Expand|Select|Wrap|Line Numbers
  1.  Project1.VBCls obj = new Project1.VBCls();
  2.  Console.WriteLine(obj.GetHandleCount());
  3.  
Please find my next post for question...
Oct 6 '08 #1
9 3738
Post Cont...


When I run the C#.NET application getting the exception
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HandleCountSample.exe
Additional information: Exception from HRESULT: 0x80041003.

what is the solution of this error.
I observed that This line is giving exception
Set objRefreshableItem = objRefresher.AddEnum(objServicesCimv2, "Win32_PerfFormattedData_PerfProc_Process").

Please give me any solution.
Oct 6 '08 #2
Plater
7,872 Expert 4TB
Well, I don't know why you are using an old VB DLL, when WMI is fully supported in .NET, but don't you need to use DLLImport when using an unmanaged resource like your VB DLL?
Oct 6 '08 #3
Well, I don't know why you are using an old VB DLL, when WMI is fully supported in .NET, but don't you need to use DLLImport when using an unmanaged resource like your VB DLL?
Thanks for your reply.

I think there is no Refresh method in C#.Net like SWbemRefresher.Refresh . Do you know any equivalent method for that in C#.Net to refresh the Objects.
to make use of Refresh method I am calling vb 6.0 method in C#.Net.
I Tried with DllImport also, It is giving the error "entry point not found" in vb 6.0 dll . If you have any solution for this, please provide that steps.
Oct 7 '08 #4
Plater
7,872 Expert 4TB
When you use the DLL with DLLImport, you have to specify which public functions/objects you want to use I think.

And what do you mean by "refresh"? Just running the query again?
Oct 7 '08 #5
Frinavale
9,735 Expert Mod 8TB
Thanks for your reply.

I think there is no Refresh method in C#.Net like SWbemRefresher.Refresh . Do you know any equivalent method for that in C#.Net to refresh the Objects.
to make use of Refresh method I am calling vb 6.0 method in C#.Net.
I Tried with DllImport also, It is giving the error "entry point not found" in vb 6.0 dll . If you have any solution for this, please provide that steps.

What does the "Refresh" method do?

It sounds like you are going to have to Marshal your VB 6 code so that .NET knows how to use it properly.

It would really simplify your life if you could just write a method in .NET that "Refreshes" your objects instead of using unmanaged code to do this.

-Frinny
Oct 7 '08 #6
What does the "Refresh" method do?

It sounds like you are going to have to Marshal your VB 6 code so that .NET knows how to use it properly.

It would really simplify your life if you could just write a method in .NET that "Refreshes" your objects instead of using unmanaged code to do this.

-Frinny
Please check this link which talks about the "Refresh" method. It Updates information. http://msdn.microsoft.com/en-us/library/aa392091(VS.85).aspx

When I use the DLL with DLLImport, how and where to specify the public functions/objects that I want to use.
Oct 8 '08 #7
zubair1
79
When I use the DLL with DLLImport, how and where to specify the public functions/objects that I want to use.
Expand|Select|Wrap|Line Numbers
  1. [DllImport("MyDLL.dll", CharSet = CharSet.Unicode)] 
  2. public bool MyFuncEx(string exName) 
  3. }
  4.  
Oct 8 '08 #8
Plater
7,872 Expert 4TB
The refresher sounds just like you are receiving an event from WMI. That can be done as well in .NET
Oct 8 '08 #9
You should just be able to add a project reference to the com dll, Doing this will invoke the type library importer and create a callable wrapper for you COM library. The you can just use it. You dont need to get into writing you own interop signatures when you only using basic types.
Oct 8 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
6
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference...
14
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
15
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
11
by: briankirkpatrick | last post by:
Forgive me if my post seems a little amateurish... I'm requesting assistance from some of you smart folks out there to get the managed calls write that meet the specification in the esa.h for...
16
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.