Results 1 to 6 of 6

Thread: conversion problems

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    conversion problems

    I have an API I have to interact with which was originally written in Delphi.
    It contains a method which needs an integer passed to it which represents the handle to the current window.

    The problem is that in .net as far as I can see the handle to the current window is of IntPtr type and cannot be converted to an int type.

    e.g.
    Code:
     
    System.IntPtr myHandle = this.Handle;
    workflowAPI.myMethod(Convert.ToInt32(myHandle));
    
    Error "Unable to cast object of type System.IntPtr" to type "System.IConvertible"
    Any Ideas Chaps and Chapesses ?


    Parksie

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: conversion problems

    Why, is it too hot for you? :rofl:

    Try

    Code:
     [DllImport("user32.dll")] 
    	    public static extern int FindWindow(string strclassName, string strWindowName);
    Then use FindWindow to get the int value, passing it to myMethod. Just remember not to fly off it during the process. :rofl: :rofl: :rofl: :rofl:

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: conversion problems

    Try the IntPtr.ToInt32 method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: conversion problems

    Or declare the parameter as IntPtr in the first place; assuming it's a standard DLL.

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: conversion problems

    Thanks all

    I ended up parsing it to string and it magically worked.

    Parksie

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: conversion problems

    I like overcomplicating everything.

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