Results 1 to 3 of 3

Thread: Win32 API calls

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    2

    Question Win32 API calls

    Hello!
    Following code take twice the time in VB .NET than in VB6. The large number of loop is there because otherwise it is´nt possible to meassure the time.

    This was a simple task, but it seems to be the same trouble with OCX components created in C++. I tried to switch of the stack trace but this seem to put even more time to the call.

    Is it the RCW that takes time?
    Or is there any other problems?
    I mean a ordinary loop is much faster in .NET than VB 6.

    Private Sub TickBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TickBtn.Click

    Dim StartTime As Double
    Dim EndTime As Double
    Dim i As Integer
    Dim answer As Double

    StartTime = GetTickCount
    For i = 0 To 100000
    test = GetTickCount()
    Next
    EndTime = GetTickCount
    answer = EndTime - StartTime
    TimeLbl.Text = answer / 1000
    End Sub

    'Other module
    Module Global
    '<SecurityPermission(SecurityAction.Assert, _
    'Flags:=SecurityPermissionFlag.UnmanagedCode)> _
    Declare Auto Function GetTickCount Lib "kernel32" () As Integer
    End Module

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    the framework provides its own way of Getting Ticks...using API involves interop services which use more overhead

    I think the .net way is System.GetTicks...or something like that..I cant remember although Ive answered this a couple time ..Try searching the forum for it.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    2
    Thanks!

    The function is located at System.Environment.TickCount.

    So it seem to be a overhead time of 500% (Interop) percent calling a API function instead of a framework function.

    A call to the .NET framework is 25% slower than a similiar call from VB 6 to the Win 32 API.

    OK, this seem to be a fact.
    Last edited by Alfven; May 23rd, 2002 at 02:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width