DllImport / unmanaged code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim

    #1

    DllImport / unmanaged code

    I am extremely frustrated. I am building c# application
    for a call center and am using a third party API to access
    some hardware. When develop and test my class using the
    windows console the application runs flawlessly, but once
    I call the class from inside a c# windows application the
    program freezes, crashes etc...

    there must be a way to make this work inside a windows app
    as it run great as a command line app.

    Please any ideas would be welcomed at this trying time in
    my life

    Jim
  • larry

    #2
    Re: DllImport / unmanaged code

    Are you using win98?

    Does it use System.Timers.T imer on Win98? I found that there appears to be
    a threadpool problem(my guess here) in win98 with these that causes the
    timers (all of them) to freeze. The main ui still responds, but the timer
    events stop. I replaced the System.Timers.T imer with
    System.Windows. Forms.Timer and the application started working. This was
    with .NET 1.1.

    -Larry

    "Jim" <jenglish@natio nsfirstcorp.com > wrote in message
    news:075101c3ba 87$c1f5f960$a00 1280a@phx.gbl.. .[color=blue]
    > I am extremely frustrated. I am building c# application
    > for a call center and am using a third party API to access
    > some hardware. When develop and test my class using the
    > windows console the application runs flawlessly, but once
    > I call the class from inside a c# windows application the
    > program freezes, crashes etc...
    >
    > there must be a way to make this work inside a windows app
    > as it run great as a command line app.
    >
    > Please any ideas would be welcomed at this trying time in
    > my life
    >
    > Jim[/color]


    Comment

    • Jim

      #3
      Re: DllImport / unmanaged code

      I am using XP Pro on all machines, client and development.

      I am using a Timer, and I will test this with the timers
      off and post the findings. The timer I am using is the
      System.Windows. Forms.Timer.

      [color=blue]
      >-----Original Message-----
      >Are you using win98?
      >
      >Does it use System.Timers.T imer on Win98? I found that[/color]
      there appears to be[color=blue]
      >a threadpool problem(my guess here) in win98 with these[/color]
      that causes the[color=blue]
      >timers (all of them) to freeze. The main ui still[/color]
      responds, but the timer[color=blue]
      >events stop. I replaced the System.Timers.T imer with
      >System.Windows .Forms.Timer and the application started[/color]
      working. This was[color=blue]
      >with .NET 1.1.
      >
      >-Larry
      >
      >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
      >news:075101c3b a87$c1f5f960$a0 01280a@phx.gbl. ..[color=green]
      >> I am extremely frustrated. I am building c#[/color][/color]
      application[color=blue][color=green]
      >> for a call center and am using a third party API to[/color][/color]
      access[color=blue][color=green]
      >> some hardware. When develop and test my class using the
      >> windows console the application runs flawlessly, but[/color][/color]
      once[color=blue][color=green]
      >> I call the class from inside a c# windows application[/color][/color]
      the[color=blue][color=green]
      >> program freezes, crashes etc...
      >>
      >> there must be a way to make this work inside a windows[/color][/color]
      app[color=blue][color=green]
      >> as it run great as a command line app.
      >>
      >> Please any ideas would be welcomed at this trying time[/color][/color]
      in[color=blue][color=green]
      >> my life
      >>
      >> Jim[/color]
      >
      >
      >.
      >[/color]

      Comment

      • Jim

        #4
        Re: DllImport / unmanaged code

        removed all timers and still crashing.

        extremely frustrating as this is the same class I use as a
        command line appliation.

        [color=blue]
        >-----Original Message-----
        >Are you using win98?
        >
        >Does it use System.Timers.T imer on Win98? I found that[/color]
        there appears to be[color=blue]
        >a threadpool problem(my guess here) in win98 with these[/color]
        that causes the[color=blue]
        >timers (all of them) to freeze. The main ui still[/color]
        responds, but the timer[color=blue]
        >events stop. I replaced the System.Timers.T imer with
        >System.Windows .Forms.Timer and the application started[/color]
        working. This was[color=blue]
        >with .NET 1.1.
        >
        >-Larry
        >
        >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
        >news:075101c3b a87$c1f5f960$a0 01280a@phx.gbl. ..[color=green]
        >> I am extremely frustrated. I am building c#[/color][/color]
        application[color=blue][color=green]
        >> for a call center and am using a third party API to[/color][/color]
        access[color=blue][color=green]
        >> some hardware. When develop and test my class using the
        >> windows console the application runs flawlessly, but[/color][/color]
        once[color=blue][color=green]
        >> I call the class from inside a c# windows application[/color][/color]
        the[color=blue][color=green]
        >> program freezes, crashes etc...
        >>
        >> there must be a way to make this work inside a windows[/color][/color]
        app[color=blue][color=green]
        >> as it run great as a command line app.
        >>
        >> Please any ideas would be welcomed at this trying time[/color][/color]
        in[color=blue][color=green]
        >> my life
        >>
        >> Jim[/color]
        >
        >
        >.
        >[/color]

        Comment

        • Jim

          #5
          DllImport / unmanaged code

          Ok, I have been researching and I just found an
          interesting statement. PINVOKE is designed for WIN32 API
          calls only. Is this true? I have trying to use PInvoke
          to call a third party API Inside the WIN32 System
          directory. Could this be causing my error?

          Jim[color=blue]
          >-----Original Message-----
          >I am extremely frustrated. I am building c# application
          >for a call center and am using a third party API to[/color]
          access[color=blue]
          >some hardware. When develop and test my class using the
          >windows console the application runs flawlessly, but once
          >I call the class from inside a c# windows application the
          >program freezes, crashes etc...
          >
          >there must be a way to make this work inside a windows[/color]
          app[color=blue]
          >as it run great as a command line app.
          >
          >Please any ideas would be welcomed at this trying time in
          >my life
          >
          >Jim
          >.
          >[/color]

          Comment

          • Mountain Bikn' Guy

            #6
            Re: DllImport / unmanaged code

            Some possibilities come to mind:
            1. does your code call any controls on the WinForms portion from another
            thread?
            2. I recently had a problem where the unmanaged code was stepping on memory.
            It gave results similar to what you are seeing. It ran fine for a long time,
            but when I introduced some new forms (and another thread) the error began
            causing problems. It only showed up when a form was loaded. But the error
            had nothing to do with the form. It was related to the unmanaged code
            stepping on memory (an array issue).

            In general, calling unmanaged code from a WinForms app works fine. So you
            must have a bug somewhere.

            I hope those ideas help.

            "Jim" <jenglish@natio nsfirstcorp.com > wrote in message
            news:075101c3ba 87$c1f5f960$a00 1280a@phx.gbl.. .[color=blue]
            > I am extremely frustrated. I am building c# application
            > for a call center and am using a third party API to access
            > some hardware. When develop and test my class using the
            > windows console the application runs flawlessly, but once
            > I call the class from inside a c# windows application the
            > program freezes, crashes etc...
            >
            > there must be a way to make this work inside a windows app
            > as it run great as a command line app.
            >
            > Please any ideas would be welcomed at this trying time in
            > my life
            >
            > Jim[/color]


            Comment

            • Mountain Bikn' Guy

              #7
              Re: DllImport / unmanaged code

              No. PInvoke can call (virtually) any DLL. I've called C and C++ DLLs of many
              different types, some not even written specifically for the latest/newest
              versions of Windows OS's.

              "Jim" <jenglish@natio nsfirstcorp.com > wrote in message
              news:026701c3ba 8e$fb6c7fa0$a10 1280a@phx.gbl.. .[color=blue]
              > Ok, I have been researching and I just found an
              > interesting statement. PINVOKE is designed for WIN32 API
              > calls only. Is this true? I have trying to use PInvoke
              > to call a third party API Inside the WIN32 System
              > directory. Could this be causing my error?
              >[/color]


              Comment

              • Eric Gunnerson [MS]

                #8
                Re: DllImport / unmanaged code

                Jim,

                It's possible with P/Invoke to define things so that that they work
                sometimes, but stop working if the environment changes a little. Can you
                post the P/Invoke code you've written (both the functions and the calls),
                along with the headers for the functions you're calling?

                --
                Eric Gunnerson

                Visit the C# product team at http://www.csharp.net
                Eric's blog is at http://blogs.gotdotnet.com/ericgu/

                This posting is provided "AS IS" with no warranties, and confers no rights.
                "Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                news:026701c3ba 8e$fb6c7fa0$a10 1280a@phx.gbl.. .[color=blue]
                > Ok, I have been researching and I just found an
                > interesting statement. PINVOKE is designed for WIN32 API
                > calls only. Is this true? I have trying to use PInvoke
                > to call a third party API Inside the WIN32 System
                > directory. Could this be causing my error?
                >
                > Jim[color=green]
                > >-----Original Message-----
                > >I am extremely frustrated. I am building c# application
                > >for a call center and am using a third party API to[/color]
                > access[color=green]
                > >some hardware. When develop and test my class using the
                > >windows console the application runs flawlessly, but once
                > >I call the class from inside a c# windows application the
                > >program freezes, crashes etc...
                > >
                > >there must be a way to make this work inside a windows[/color]
                > app[color=green]
                > >as it run great as a command line app.
                > >
                > >Please any ideas would be welcomed at this trying time in
                > >my life
                > >
                > >Jim
                > >.
                > >[/color][/color]


                Comment

                • Jim

                  #9
                  Re: DllImport / unmanaged code

                  Here is the code

                  using System;
                  using System.Runtime. InteropServices ;
                  using System.Threadin g;
                  using System.Componen tModel;

                  namespace MarketingRep
                  {
                  /// <summary>
                  /// Summary description for Pika.
                  /// </summary>
                  public class Pika
                  {

                  /*************** *************** *************** *****
                  *************
                  * Create a delegate for our callback
                  function.
                  *
                  *************** *************** *************** **************
                  */
                  unsafe public delegate void EventHandlerCB
                  (void* vpUserData, uint uiEvent, uint uiParam0, uint
                  uiParam1);


                  /*************** *************** *************** *****
                  ************
                  * enumeration for networkinterfac e types
                  for pika voice card
                  * we are using a headset, value 5
                  *
                  *************** *************** *************** **************
                  */
                  public enum TNetworkInterfa ceType
                  {
                  PK_CONFIG_NI_NO NE
                  = 0,
                  PK_CONFIG_NI_LS _TRUNK
                  = 1,
                  PK_CONFIG_NI_PH ONE
                  = 2,
                  PK_CONFIG_NI_DI D_TRUNK
                  = 3,
                  PK_CONFIG_NI_EM _TRUNK
                  = 4,
                  PK_CONFIG_NI_HE ADSET
                  = 5,
                  PK_CONFIG_NI_DI GITAL
                  = 6
                  }

                  /*
                  * Trunk device states
                  */
                  public enum TTrunkHookState
                  {
                  PK_TRUNK_INVALI D,
                  PK_TRUNK_OFFHOO KING,
                  PK_TRUNK_OFFHOO K,
                  PK_TRUNK_ONHOOK ING,
                  PK_TRUNK_ONHOOK ,
                  PK_TRUNK_HOOKFL ASHING,
                  PK_TRUNK_DIALIN G,
                  PK_TRUNK_WINKIN G,
                  PK_TRUNK_GROUND _BUTTON
                  }


                  /*************** *************** *************** *****
                  ************
                  * GROUP based Voice Conference Definitions
                  *
                  *************** *************** *************** **************
                  */

                  public enum TGroupMode
                  {
                  PK_VC_GroupMode _Sampling
                  = 0,
                  PK_VC_GroupMode _Summation
                  = 1
                  }

                  public struct TGroupParameter s
                  {
                  public TGroupMode groupMode;
                  }



                  /*************** *************** *************** *****
                  *************** *
                  * Event struct for callback funtion

                  *************** *************** *************** **************
                  ******/
                  public struct SEventQ
                  {
                  public uint uiUserData;
                  public uint uiEvent;
                  public uint uiParam0;
                  public uint uiParam1;
                  }
                  SEventQ[] EvQ = new SEventQ[200];
                  // int iQOut = 0;
                  int iQIn = 0;

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_CTI_NumberOf Boards();

                  [DllImport("Pika API.dll")]
                  public static extern uint PK_CTI_Initiali ze
                  (uint TBoardIndex);

                  [DllImport("Pika API.dll")]
                  public static extern uint PK_CTI_Start
                  (uint TBoardIndex);

                  [DllImport("Pika API.dll")]
                  public static extern uint PK_CTI_StopDriv er
                  (uint TBoardIndex);

                  [DllImport("Pika API.dll")]
                  unsafe public static extern int
                  PK_BOARD_SetEve ntHandler(uint TResourceHandle , void*
                  PK_VOID, EventHandlerCB EventHandler);

                  [DllImport("Pika API.dll")]
                  unsafe public static extern int
                  PK_DSP_DEVICE_S etEventHandler( uint TResourceHandle , void*
                  PK_VOID, EventHandlerCB EventHandler);

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_DSP_GetDevic eHandle(uint TBoardIndex, uint PK_Word);

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_DSP_DEVICE_G etPortHandle(ui nt TResourceHandle , uint
                  PK_WORD);

                  [DllImport("Pika API.dll")]
                  unsafe public static extern uint
                  PK_DSP_PORT_Set EventHandler(ui nt TResourceHandle , void*
                  PK_VOID, EventHandlerCB EventHandler);

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_AUDIO_SetFor mat(uint TResourceHandle , uint
                  TAudioFormat);

                  [DllImport("Pika API.dll")]
                  public static extern uint PK_VC_AddMember
                  (uint TGroupHandle, uint TResourceHandle , int TGainLevel,
                  int TGainLevel1, uint PK_BOOL);

                  [DllImport("Pika API.dll")]
                  unsafe public static extern uint
                  PK_VC_SetGroupP arameters(uint TGroupHandle, void*
                  TGroupParameter s);

                  [DllImport("Pika API.dll")]
                  public static extern uint PK_VC_CreateGro up
                  (uint TDeviceHandle);

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_PHONE_SeizeR esource(uint TBoardIndex,
                  TNetworkInterfa ceType interfaceEnum);

                  [DllImport("Pika API.dll")]
                  unsafe public static extern uint
                  PK_PHONE_SetEve ntHandler(uint TResourceHandle , void*
                  PK_VOID, EventHandlerCB EventHandler);

                  [DllImport("Pika API.dll")]
                  public static extern int PK_TRUNK_OffHoo k
                  (uint TResourceHandle );

                  [DllImport("Pika API.dll")]
                  public static extern int PK_TRUNK_OnHook
                  (uint TResourceHandle );

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_TRUNK_Create Resource(uint TBoardIndex, uint PK_WORD);

                  [DllImport("Pika API.dll")]
                  unsafe public static extern uint
                  PK_TRUNK_SetEve ntHandler(uint TResourceHandle , void*
                  PK_VOID, EventHandlerCB EventHandler);

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_TRUNK_CallOf ferDetection(ui nt TResourceHandle , uint
                  PK_BOOL);

                  [DllImport("Pika API.dll")]
                  public static extern uint
                  PK_TRUNK_Discon nectDetection(u int TResourceHandle , uint
                  PK_BOOL);

                  [DllImport("Pika API.dll")]
                  public static extern TTrunkHookState
                  PK_TRUNK_GetHoo kState(uint TResourceHandle );



                  /*************** *************** *************** *****
                  ********
                  * Global Variables
                  *
                  *************** *************** *************** **********/
                  uint hDSP = 0;
                  uint hGroup = 0;
                  uint hTrunk = 0;
                  uint uiBoardIndex = 0;
                  uint hMemberTrunk = 0;
                  uint hMemberHeadset = 0;
                  uint hHeadset = 0;
                  // uint hMemberDialInpu t = 0;
                  // uint hMemberDialOutp ut = 0;
                  // uint hMemberToneDete ctOutput = 0;
                  // uint hMemberToneDete ctInput = 0;
                  uint uiNumberOfBoard s = 0;

                  const int PK_AUDIO_FORMAT _MU_LAW
                  = 0x00000020; /* Default */
                  const int PK_AUDIO_SAMPLI NG_RATE_8_KHz =
                  0x00000000; /* Default */

                  const uint PK_SUCCESS = 0;
                  const uint PK_TRUE = 1;
                  const uint PK_FALSE = 0;

                  //EVENT CODES
                  const uint PK_EVENT_TRUNK_ OFFHOOK = 512;
                  const uint PK_EVENT_TRUNK_ ONHOOK =
                  0x00000201;
                  const uint PK_EVENT_TRUNK_ BUSY =522;

                  //RETURN CODES
                  const int PK_DRV_E_INVALI D_RESOURCE = -102;
                  const int PK_TRUNK_E_NOT_ OFFHOOK = -350;
                  const int PK_TRUNK_E_NOT_ ONHOOK = -351;

                  public Pika()
                  {
                  if(InitializeBo ard())
                  {
                  //Console.Write(" Board
                  Initialized");
                  }
                  else
                  {
                  //Console.Write(" No Board
                  Found");
                  }

                  if(GetResources ())
                  {
                  //Console.Write(" Finished
                  getting Resource Handles\r\n\r\n ");
                  }
                  else
                  {
                  //Console.Write(" Error
                  getting Resource Handles \r\n");
                  }


                  /*************** *************** *************** *****
                  *************** **
                  * start the process
                  *
                  *************** *************** *************** **************
                  ****/

                  if(PK_VC_AddMem ber(hGroup,
                  hMemberTrunk, 240, 0, PK_FALSE) == PK_SUCCESS)
                  {
                  if(PK_VC_AddMem ber(hGroup,
                  hMemberHeadset, 0,0, PK_FALSE) == PK_SUCCESS)
                  {
                  //if
                  (PK_VC_AddMembe r(hGroup, hMemberDialInpu t, 0,0, PK_FALSE)
                  == PK_SUCCESS)
                  //{
                  // if
                  (PK_VC_AddMembe r(hGroup, hMemberToneDete ctOutput, 0,0,
                  PK_FALSE) == PK_SUCCESS)
                  // {

                  TGroupParameter s GroupParameters = new
                  TGroupParameter s();

                  GroupParameters .groupMode = new TGroupMode();

                  unsafe
                  {

                  if(PK_VC_SetGro upParameters(hG roup,
                  &GroupParameter s) == PK_SUCCESS)

                  {

                  //Console.Write(" Group parameters set");

                  }

                  else

                  {

                  //Console.Write(" Error setting group
                  Parameters");

                  }
                  }
                  // }
                  //}
                  }
                  else
                  {
                  //Console.Write
                  ("Add Member headset error");
                  }
                  }
                  else
                  {
                  //Console.Write(" Add
                  member Group error");
                  }
                  }


                  /*************** *************** *************** *****
                  *************** ****
                  *
                  * InitializeBoard
                  *
                  *
                  *************** *************** *************** **************
                  *******/
                  private bool InitializeBoard ()
                  {
                  uiNumberOfBoard s =
                  PK_CTI_NumberOf Boards();

                  // Check for found board if none
                  return false;
                  if(uiNumberOfBo ards > 0)
                  {
                  // Initialize the board

                  if(PK_CTI_Initi alize
                  (uiBoardIndex) == 0)
                  {
                  //Console.Write
                  ("Board Initialized\r\n ");
                  }
                  else
                  {
                  return false;
                  }

                  if(PK_CTI_Start
                  (uiBoardIndex) == 0)
                  {
                  Console.Write(" Board
                  Started\r\n");
                  }
                  else
                  {
                  return false;
                  }
                  return true;
                  }
                  else
                  {
                  //Console.Write(" No Boards
                  Found\r\n");
                  return false;
                  }

                  }


                  /*************** *************** *************** *****
                  *************** *
                  * GetResources
                  * gets the DSP information and sets all
                  ports for usage
                  *
                  *************** *************** *************** **************
                  ****/
                  private bool GetResources()
                  { //Set Board Event Handler
                  unsafe
                  {
                  EventHandlerCB EB = new
                  EventHandlerCB( EventHandler);
                  if
                  ((PK_BOARD_SetE ventHandler(0, (void*)5000, EB)) !=
                  PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set Trunk Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP Trunk Event Handler set \r\n");
                  }
                  }


                  //Get the handle of DSP 0 on Board
                  0
                  if((hDSP = PK_DSP_GetDevic eHandle
                  (0, uiBoardIndex)) == Convert.ToUInt3 2(null))
                  {
                  return false;


                  }
                  else
                  {
                  //Console.Write
                  ("\r\nDevice Handle: " + hDSP + "\r\n");
                  }

                  //Set Board Event Handler
                  unsafe
                  {
                  EventHandlerCB E = new
                  EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_DEVICE _SetEventHandle r(hDSP, (void*)uiBoardI ndex,
                  E)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set Trunk Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP Trunk Event Handler set \r\n");
                  }
                  }



                  /*************** *************** *************** *****
                  *************
                  * use this section to get all port
                  information
                  * needed for Inline MM to be abel
                  to assign your input
                  * and output ports.
                  *
                  // Get number of ports
                  with enabled applications
                  uint NumPorts =
                  PK_DSP_DEVICE_N umberOfPorts(hD SP);

                  //get all port handles
                  uint[] handleArray = new
                  uint[NumPorts];
                  for(uint i = 0; i <
                  NumPorts; i++)
                  {
                  handleArray[i] =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, i);
                  }

                  for(int z=0; z < NumPorts;
                  z++)
                  {
                  //Console.Write
                  ("\r\n" + handleArray[z].ToString());
                  }
                  //Console.Write
                  ("\r\n\r\n") ;
                  TResourceDesc trd = new
                  TResourceDesc() ;
                  for(uint d = 0; d<
                  NumPorts; d++)
                  {
                  uint y =
                  handleArray[d];

                  PK_DSP_PORT_Get ResourceDesc(ha ndleArray[d], ref
                  trd);

                  //Console.Write(h andleArray[d].ToString());

                  //Console.Write(" \r\nSwitch Index: " +
                  trd.hSwDev.ToSt ring());

                  //Console.Write(" \r\nDevice Handle: " +
                  trd.hDev.ToStri ng());

                  //Console.Write(" \r\nSwitch Input Port: " +
                  trd.inPort.ToSt ring());

                  //Console.Write(" \r\nSwitch Output Port: " +
                  trd.outPort.ToS tring());

                  //Console.Write(" \r\nResource Mask: " +
                  trd.resMask.ToS tring());

                  //Console.Write(" \r\n\r\n");
                  }

                  */

                  // Get Handle fo Trunk Conference
                  Port
                  if((hMemberTrun k =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, 0)) == Convert.ToUInt3 2
                  (null))
                  {
                  //Console.Write(" Could Not
                  Seize Trunk Port");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Trunk
                  Port Seied\r\n");
                  }

                  //Set trunk event handler
                  unsafe
                  {
                  EventHandlerCB EH = new
                  EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_PORT_S etEventHandler( hMemberTrunk, (void*)
                  hMemberTrunk, EH)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set Trunk Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP Trunk Event Handler set \r\n");
                  }
                  }

                  //Get handle of headset conference
                  port
                  if((hMemberHead set =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, 1)) == Convert.ToUInt3 2
                  (null))
                  {
                  //Console.Write(" Could Not
                  Seize Headset Port");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Headset
                  Port Seized\r\n");
                  }


                  //get Output port for DTMF dialing
                  //
                  /* if((hMemberDial Output =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, 4)) == Convert.ToUInt3 2
                  (null))
                  {
                  //Console.Write(" Could Not
                  Seize dmtf Port");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" dmtf Port
                  Seized\r\n");
                  }

                  //Set trunk event handler
                  unsafe
                  {
                  EventHandlerCB EvetHandler
                  = new EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_PORT_S etEventHandler( hMemberDialOutp ut, (void*)
                  hMemberDialOutp ut, EvetHandler)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set dmtf Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP dtmf Event Handler set \r\n");
                  }
                  }

                  //get Input port for DTMF dialing
                  //
                  if((hMemberDial Input =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, 15)) == Convert.ToUInt3 2
                  (null))
                  {
                  //Console.Write(" Could Not
                  input Seize dmtf Port");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" dmtf
                  input Port Seized\r\n");
                  }

                  //Set trunk event handler
                  unsafe
                  {
                  EventHandlerCB EHan = new
                  EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_PORT_S etEventHandler( hMemberDialInpu t, (void*)
                  hMemberDialInpu t, EHan)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set dmtf Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP dtmf Event Handler set \r\n");
                  }
                  }
                  */
                  // SEt Trunk Audio
                  if((PK_AUDIO_Se tFormat
                  (hMemberTrunk, (PK_AUDIO_FORMA T_MU_LAW |
                  PK_AUDIO_SAMPLI NG_RATE_8_KHz)) ) != PK_SUCCESS)
                  {
                  //Console.Write(" Could Not
                  Set Trunk Audio");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Trunk
                  Audio Set\r\n");
                  }

                  // Set Headset Audio
                  if((PK_AUDIO_Se tFormat
                  (hMemberHeadset , (PK_AUDIO_FORMA T_MU_LAW |
                  PK_AUDIO_SAMPLI NG_RATE_8_KHz)) ) != PK_SUCCESS)
                  {
                  //Console.Write(" Could Not
                  Set Headset Audio");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Headset
                  Audio Set\r\n");
                  }
                  //Set trunk event handler
                  unsafe
                  {
                  EventHandlerCB EHa = new
                  EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_PORT_S etEventHandler( hMemberHeadset, (void*)
                  hMemberHeadset, EHa)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set Trunk Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP Trunk Event Handler set \r\n");
                  }
                  }

                  // Get Handle for conference group
                  if((hGroup = PK_VC_CreateGro up
                  (hDSP)) == Convert.ToUInt3 2(null))
                  {
                  //Console.Write(" Could set
                  Conference group");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("Conference group set");
                  }

                  //get headset handle of trunk 0 on
                  board 0
                  // seize headset handle get trunk
                  1 board 0
                  TNetworkInterfa ceType IType = new
                  TNetworkInterfa ceType();
                  IType = (TNetworkInterf aceType)5;
                  if((hHeadset =
                  PK_PHONE_SeizeR esource(uiBoard Index, IType)) ==
                  Convert.ToUInt3 2(null))
                  {
                  //Console.Write(" ERROR
                  Retrieving Headset Handle");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Headset
                  Handle: " + hHeadsetHandle + "\r\n");
                  }

                  // Get second port for tone
                  Detection.
                  /* //Tone Detection input
                  if((hMemberTone DetectInput =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, 16)) == Convert.ToUInt3 2
                  (null))
                  {
                  //Console.Write(" Could Not
                  input Seize Tone Detect Port");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" tone
                  detection input Port Seized\r\n");
                  }

                  //Set trunk event handler
                  unsafe
                  {
                  EventHandlerCB EvetHandle
                  = new EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_PORT_S etEventHandler( hMemberToneDete ctInput,
                  (void*)hMemberT oneDetectInput, EvetHandle)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set tone dectetion input Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP tone detect input Event Handler set \r\n");
                  }
                  }

                  // Tone detection output.
                  //
                  if((hMemberTone DetectOutput =
                  PK_DSP_DEVICE_G etPortHandle(hD SP, 5)) == Convert.ToUInt3 2
                  (null))
                  {
                  //Console.Write(" Could Not
                  iOutput Seize Tone Detect Port");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" tone
                  detection Output Port Seized\r\n");
                  }



                  //Set trunk event handler
                  unsafe
                  {
                  EventHandlerCB EHand = new
                  EventHandlerCB( EventHandler);
                  if
                  ((PK_DSP_PORT_S etEventHandler( hMemberToneDete ctOutput,
                  (void*)hMemberT oneDetectOutput , EHand)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not set tone dectetion Output Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP tone detect Output Event Handler set \r\n");
                  }
                  }
                  //Load the tone file onto the DSP
                  int iErrorCode = 0;
                  if((iErrorCode =
                  PK_VP_SetToneAl lGroupsDescFrom File(hDSP, "C:\\Docume nts
                  and Settings\\Jim English\\My Documents\\Visu al Studio
                  Projects\\Pika_ Test\\Tone_file .tb")) != PK_SUCCESS)
                  {
                  //Console.Write(" Could Not
                  UPLOAD TONE FILE " + iErrorCode + "\r\n");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" TONE FILE
                  UPLOADED \r\n");
                  }

                  //Set the tones ont he ports
                  if(PK_VP_Includ eToneEx
                  (hMemberToneDet ectInput, TONE_DIALTONE) != PK_SUCCESS)
                  {
                  //Console.Write(" Dial Tone
                  not loaded \r\n");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" DIal tone
                  loaded \r\n");
                  }

                  if(PK_VP_Includ eToneEx
                  (hMemberToneDet ectInput, TONE_BUSY) != PK_SUCCESS)
                  {
                  ////Console.Write(" BUSY
                  Tone not loaded \r\n");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" BUSY tone
                  loaded \r\n");
                  }

                  if(PK_VP_Includ eToneEx
                  (hMemberToneDet ectInput, TONE_RINGBACK) != PK_SUCCESS)
                  {
                  //Console.Write(" RINGBACK
                  Tone not loaded \r\n");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" RINGBACK
                  tone loaded \r\n");
                  }


                  /*************** *************** *************** *****
                  *************** ***
                  * enable tone
                  dection
                  */ // * ****/
                  // PK_VP_EnableTon eDetection
                  (hMemberToneDet ectInput);

                  // get handle of trunk 0 on board 0
                  if((hTrunk =
                  PK_TRUNK_Create Resource(uiBoar dIndex, 0)) ==
                  Convert.ToUInt3 2(null))
                  {
                  //Console.Write(" Error
                  getting trunk handle");
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Trunk
                  handle retrieved\r\n") ;
                  }


                  // SetTrunk event handler
                  unsafe
                  {
                  EventHandlerCB EvtHandl =
                  new EventHandlerCB( EventHandler);
                  if
                  ((PK_TRUNK_SetE ventHandler(hTr unk, (void*)hTrunk,
                  EvtHandl)) != PK_SUCCESS)
                  {
                  //Console.Write
                  ("Could Not Trunk Event Handler");
                  return false;
                  }
                  else
                  {
                  //Console.Write
                  ("DSP Trunk Event Handler set \r\n");
                  }
                  }

                  if((PK_TRUNK_Di sconnectDetecti on
                  (hTrunk, PK_TRUE)) != PK_SUCCESS)
                  {
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Trunk
                  Disconnection Enabled \r\n");
                  }

                  if((PK_TRUNK_Ca llOfferDetectio n
                  (hTrunk, PK_TRUE)) != PK_SUCCESS)
                  {
                  return false;
                  }
                  else
                  {
                  //Console.Write(" Trunk
                  Call Offer Detection Enabled \r\n");

                  }
                  return true;

                  }


                  /*************** *************** *************** *****
                  *************** ******
                  * EventHandler
                  * Callback function for Pika API
                  *
                  *************** *************** *************** **************
                  *********/
                  unsafe public void EventHandler (void*
                  vpUserData, uint uiEvent, uint uiParam0, uint uiParam1)
                  {
                  lock(EvQ)
                  {
                  EvQ[iQIn].uiUserData =
                  (uint)vpUserDat a;
                  EvQ[iQIn].uiEvent =
                  uiEvent;
                  EvQ[iQIn].uiParam0 =
                  uiParam0;
                  EvQ[iQIn].uiParam1 =
                  uiParam1;

                  //Console.Write(" \r\nEvent
                  Handler " + iQIn.ToString() );
                  //Console.Write
                  ("\r\nEvent : " + uiEvent.ToStrin g() + "\r\n");

                  iQIn ++;

                  if(iQIn == 200) //Queue at
                  max compacity
                  {
                  iQIn = 0; //Reset
                  to 0
                  }
                  }
                  }


                  public string getHookState()
                  {
                  TTrunkHookState th = new
                  TTrunkHookState ();
                  th = PK_TRUNK_GetHoo kState(hTrunk);
                  return th.ToString();
                  }

                  public string offHook()
                  {
                  int iError = 0;

                  TTrunkHookState th = new
                  TTrunkHookState ();
                  th = PK_TRUNK_GetHoo kState(hTrunk);


                  if((iError = PK_TRUNK_OffHoo k
                  (hTrunk)) != PK_SUCCESS)
                  {
                  if(iError ==
                  PK_DRV_E_INVALI D_RESOURCE)

                  return "PK_DRV_E_INVAL ID_RESOURCE";

                  else if(iError ==
                  PK_TRUNK_E_NOT_ ONHOOK)

                  return "PK_TRUNK_E_NOT _ONHOOK";

                  else
                  return "ERROR -
                  NOT DEFINED";
                  }
                  else
                  return "Off Hook!";
                  }


                  public string onHook()
                  {
                  int iE = 0;

                  if((iE = PK_TRUNK_OnHook (hTrunk)) !
                  = PK_SUCCESS)
                  {
                  if(iE ==
                  PK_DRV_E_INVALI D_RESOURCE)

                  return "PK_DRV_E_INVAL ID_RESOURCE";

                  else if(iE ==
                  PK_TRUNK_E_NOT_ ONHOOK)

                  return "PK_TRUNK_E_NOT _ONHOOK";

                  else
                  return "ERROR -
                  NOT DEFINED";
                  }
                  else
                  return "On Hook!";
                  }
                  }
                  }[color=blue]
                  >-----Original Message-----
                  >Jim,
                  >
                  >It's possible with P/Invoke to define things so that that[/color]
                  they work[color=blue]
                  >sometimes, but stop working if the environment changes a[/color]
                  little. Can you[color=blue]
                  >post the P/Invoke code you've written (both the functions[/color]
                  and the calls),[color=blue]
                  >along with the headers for the functions you're calling?
                  >
                  >--
                  >Eric Gunnerson
                  >
                  >Visit the C# product team at http://www.csharp.net
                  >Eric's blog is at http://blogs.gotdotnet.com/ericgu/
                  >
                  >This posting is provided "AS IS" with no warranties, and[/color]
                  confers no rights.[color=blue]
                  >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                  >news:026701c3b a8e$fb6c7fa0$a1 01280a@phx.gbl. ..[color=green]
                  >> Ok, I have been researching and I just found an
                  >> interesting statement. PINVOKE is designed for WIN32[/color][/color]
                  API[color=blue][color=green]
                  >> calls only. Is this true? I have trying to use PInvoke
                  >> to call a third party API Inside the WIN32 System
                  >> directory. Could this be causing my error?
                  >>
                  >> Jim[color=darkred]
                  >> >-----Original Message-----
                  >> >I am extremely frustrated. I am building c#[/color][/color][/color]
                  application[color=blue][color=green][color=darkred]
                  >> >for a call center and am using a third party API to[/color]
                  >> access[color=darkred]
                  >> >some hardware. When develop and test my class using[/color][/color][/color]
                  the[color=blue][color=green][color=darkred]
                  >> >windows console the application runs flawlessly, but[/color][/color][/color]
                  once[color=blue][color=green][color=darkred]
                  >> >I call the class from inside a c# windows application[/color][/color][/color]
                  the[color=blue][color=green][color=darkred]
                  >> >program freezes, crashes etc...
                  >> >
                  >> >there must be a way to make this work inside a windows[/color]
                  >> app[color=darkred]
                  >> >as it run great as a command line app.
                  >> >
                  >> >Please any ideas would be welcomed at this trying time[/color][/color][/color]
                  in[color=blue][color=green][color=darkred]
                  >> >my life
                  >> >
                  >> >Jim
                  >> >.
                  >> >[/color][/color]
                  >
                  >
                  >.
                  >[/color]

                  Comment

                  • Guest's Avatar

                    #10
                    Re: DllImport / unmanaged code

                    Thanks, I am getting the same results, a Null Reference
                    Exception or the window disappears and the program is
                    still running.

                    I have striped down the windows form to two buttons and a
                    textbox. and post events to the textbox and one button
                    takes the phone off hook, the other puts the phone back on
                    hook.

                    Thaks for the reply....

                    jIm[color=blue]
                    >-----Original Message-----
                    >Some possibilities come to mind:
                    >1. does your code call any controls on the WinForms[/color]
                    portion from another[color=blue]
                    >thread?
                    >2. I recently had a problem where the unmanaged code was[/color]
                    stepping on memory.[color=blue]
                    >It gave results similar to what you are seeing. It ran[/color]
                    fine for a long time,[color=blue]
                    >but when I introduced some new forms (and another thread)[/color]
                    the error began[color=blue]
                    >causing problems. It only showed up when a form was[/color]
                    loaded. But the error[color=blue]
                    >had nothing to do with the form. It was related to the[/color]
                    unmanaged code[color=blue]
                    >stepping on memory (an array issue).
                    >
                    >In general, calling unmanaged code from a WinForms app[/color]
                    works fine. So you[color=blue]
                    >must have a bug somewhere.
                    >
                    >I hope those ideas help.
                    >
                    >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                    >news:075101c3b a87$c1f5f960$a0 01280a@phx.gbl. ..[color=green]
                    >> I am extremely frustrated. I am building c#[/color][/color]
                    application[color=blue][color=green]
                    >> for a call center and am using a third party API to[/color][/color]
                    access[color=blue][color=green]
                    >> some hardware. When develop and test my class using the
                    >> windows console the application runs flawlessly, but[/color][/color]
                    once[color=blue][color=green]
                    >> I call the class from inside a c# windows application[/color][/color]
                    the[color=blue][color=green]
                    >> program freezes, crashes etc...
                    >>
                    >> there must be a way to make this work inside a windows[/color][/color]
                    app[color=blue][color=green]
                    >> as it run great as a command line app.
                    >>
                    >> Please any ideas would be welcomed at this trying time[/color][/color]
                    in[color=blue][color=green]
                    >> my life
                    >>
                    >> Jim[/color]
                    >
                    >
                    >.
                    >[/color]

                    Comment

                    • Mountain Bikn' Guy

                      #11
                      Re: DllImport / unmanaged code

                      I see the following using statement in the code you posted for Eric:
                      using System.Threadin g;

                      So I assume you have more than one thread. I also assume you know the rule
                      that any Windows control must only be updated from the main thread. If you
                      need more detail, let me know.

                      Regards,
                      Mountain

                      <anonymous@disc ussions.microso ft.com> wrote in message
                      news:0c4401c3ba c5$ad20afb0$a00 1280a@phx.gbl.. .[color=blue]
                      > Thanks, I am getting the same results, a Null Reference
                      > Exception or the window disappears and the program is
                      > still running.
                      >
                      > I have striped down the windows form to two buttons and a
                      > textbox. and post events to the textbox and one button
                      > takes the phone off hook, the other puts the phone back on
                      > hook.
                      >
                      > Thaks for the reply....
                      >
                      > jIm[color=green]
                      > >-----Original Message-----
                      > >Some possibilities come to mind:
                      > >1. does your code call any controls on the WinForms[/color]
                      > portion from another[color=green]
                      > >thread?
                      > >2. I recently had a problem where the unmanaged code was[/color]
                      > stepping on memory.[color=green]
                      > >It gave results similar to what you are seeing. It ran[/color]
                      > fine for a long time,[color=green]
                      > >but when I introduced some new forms (and another thread)[/color]
                      > the error began[color=green]
                      > >causing problems. It only showed up when a form was[/color]
                      > loaded. But the error[color=green]
                      > >had nothing to do with the form. It was related to the[/color]
                      > unmanaged code[color=green]
                      > >stepping on memory (an array issue).
                      > >
                      > >In general, calling unmanaged code from a WinForms app[/color]
                      > works fine. So you[color=green]
                      > >must have a bug somewhere.
                      > >
                      > >I hope those ideas help.
                      > >
                      > >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                      > >news:075101c3b a87$c1f5f960$a0 01280a@phx.gbl. ..[color=darkred]
                      > >> I am extremely frustrated. I am building c#[/color][/color]
                      > application[color=green][color=darkred]
                      > >> for a call center and am using a third party API to[/color][/color]
                      > access[color=green][color=darkred]
                      > >> some hardware. When develop and test my class using the
                      > >> windows console the application runs flawlessly, but[/color][/color]
                      > once[color=green][color=darkred]
                      > >> I call the class from inside a c# windows application[/color][/color]
                      > the[color=green][color=darkred]
                      > >> program freezes, crashes etc...
                      > >>
                      > >> there must be a way to make this work inside a windows[/color][/color]
                      > app[color=green][color=darkred]
                      > >> as it run great as a command line app.
                      > >>
                      > >> Please any ideas would be welcomed at this trying time[/color][/color]
                      > in[color=green][color=darkred]
                      > >> my life
                      > >>
                      > >> Jim[/color]
                      > >
                      > >
                      > >.
                      > >[/color][/color]


                      Comment

                      • Jim

                        #12
                        Re: DllImport / unmanaged code

                        Please I need more detail.

                        I am calling a class in the mainform and using the buttons
                        on the main form also. But I am kinda new to windows,
                        mostly been doing ASP.NET stuff for 1.5 years.

                        I even got a System.Runtime. InteropServices .SEHException'
                        error. Search internet but couldn't find any good
                        information.

                        Thanks,
                        Jim

                        [color=blue]
                        >-----Original Message-----
                        >I see the following using statement in the code you[/color]
                        posted for Eric:[color=blue]
                        >using System.Threadin g;
                        >
                        >So I assume you have more than one thread. I also assume[/color]
                        you know the rule[color=blue]
                        >that any Windows control must only be updated from the[/color]
                        main thread. If you[color=blue]
                        >need more detail, let me know.
                        >
                        >Regards,
                        >Mountain
                        >
                        ><anonymous@dis cussions.micros oft.com> wrote in message
                        >news:0c4401c3b ac5$ad20afb0$a0 01280a@phx.gbl. ..[color=green]
                        >> Thanks, I am getting the same results, a Null Reference
                        >> Exception or the window disappears and the program is
                        >> still running.
                        >>
                        >> I have striped down the windows form to two buttons and[/color][/color]
                        a[color=blue][color=green]
                        >> textbox. and post events to the textbox and one button
                        >> takes the phone off hook, the other puts the phone back[/color][/color]
                        on[color=blue][color=green]
                        >> hook.
                        >>
                        >> Thaks for the reply....
                        >>
                        >> jIm[color=darkred]
                        >> >-----Original Message-----
                        >> >Some possibilities come to mind:
                        >> >1. does your code call any controls on the WinForms[/color]
                        >> portion from another[color=darkred]
                        >> >thread?
                        >> >2. I recently had a problem where the unmanaged code[/color][/color][/color]
                        was[color=blue][color=green]
                        >> stepping on memory.[color=darkred]
                        >> >It gave results similar to what you are seeing. It ran[/color]
                        >> fine for a long time,[color=darkred]
                        >> >but when I introduced some new forms (and another[/color][/color][/color]
                        thread)[color=blue][color=green]
                        >> the error began[color=darkred]
                        >> >causing problems. It only showed up when a form was[/color]
                        >> loaded. But the error[color=darkred]
                        >> >had nothing to do with the form. It was related to the[/color]
                        >> unmanaged code[color=darkred]
                        >> >stepping on memory (an array issue).
                        >> >
                        >> >In general, calling unmanaged code from a WinForms app[/color]
                        >> works fine. So you[color=darkred]
                        >> >must have a bug somewhere.
                        >> >
                        >> >I hope those ideas help.
                        >> >
                        >> >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                        >> >news:075101c3b a87$c1f5f960$a0 01280a@phx.gbl. ..
                        >> >> I am extremely frustrated. I am building c#[/color]
                        >> application[color=darkred]
                        >> >> for a call center and am using a third party API to[/color]
                        >> access[color=darkred]
                        >> >> some hardware. When develop and test my class using[/color][/color][/color]
                        the[color=blue][color=green][color=darkred]
                        >> >> windows console the application runs flawlessly, but[/color]
                        >> once[color=darkred]
                        >> >> I call the class from inside a c# windows application[/color]
                        >> the[color=darkred]
                        >> >> program freezes, crashes etc...
                        >> >>
                        >> >> there must be a way to make this work inside a[/color][/color][/color]
                        windows[color=blue][color=green]
                        >> app[color=darkred]
                        >> >> as it run great as a command line app.
                        >> >>
                        >> >> Please any ideas would be welcomed at this trying[/color][/color][/color]
                        time[color=blue][color=green]
                        >> in[color=darkred]
                        >> >> my life
                        >> >>
                        >> >> Jim
                        >> >
                        >> >
                        >> >.
                        >> >[/color][/color]
                        >
                        >
                        >.
                        >[/color]

                        Comment

                        • Jim

                          #13
                          Re: DllImport / unmanaged code

                          Mountain,

                          forgot to mention the Systems.Threadi ng was there for the
                          lock() method. I needed a critical section for my event
                          queue and couldn't find anything else to make it happen
                          quikly in c#.

                          so I took it out for debuggin purposes after you reply and
                          still got the error. I think th eproblem may be in my
                          Callback Function.

                          JIm[color=blue]
                          >-----Original Message-----
                          >I see the following using statement in the code you[/color]
                          posted for Eric:[color=blue]
                          >using System.Threadin g;
                          >
                          >So I assume you have more than one thread. I also assume[/color]
                          you know the rule[color=blue]
                          >that any Windows control must only be updated from the[/color]
                          main thread. If you[color=blue]
                          >need more detail, let me know.
                          >
                          >Regards,
                          >Mountain
                          >
                          ><anonymous@dis cussions.micros oft.com> wrote in message
                          >news:0c4401c3b ac5$ad20afb0$a0 01280a@phx.gbl. ..[color=green]
                          >> Thanks, I am getting the same results, a Null Reference
                          >> Exception or the window disappears and the program is
                          >> still running.
                          >>
                          >> I have striped down the windows form to two buttons and[/color][/color]
                          a[color=blue][color=green]
                          >> textbox. and post events to the textbox and one button
                          >> takes the phone off hook, the other puts the phone back[/color][/color]
                          on[color=blue][color=green]
                          >> hook.
                          >>
                          >> Thaks for the reply....
                          >>
                          >> jIm[color=darkred]
                          >> >-----Original Message-----
                          >> >Some possibilities come to mind:
                          >> >1. does your code call any controls on the WinForms[/color]
                          >> portion from another[color=darkred]
                          >> >thread?
                          >> >2. I recently had a problem where the unmanaged code[/color][/color][/color]
                          was[color=blue][color=green]
                          >> stepping on memory.[color=darkred]
                          >> >It gave results similar to what you are seeing. It ran[/color]
                          >> fine for a long time,[color=darkred]
                          >> >but when I introduced some new forms (and another[/color][/color][/color]
                          thread)[color=blue][color=green]
                          >> the error began[color=darkred]
                          >> >causing problems. It only showed up when a form was[/color]
                          >> loaded. But the error[color=darkred]
                          >> >had nothing to do with the form. It was related to the[/color]
                          >> unmanaged code[color=darkred]
                          >> >stepping on memory (an array issue).
                          >> >
                          >> >In general, calling unmanaged code from a WinForms app[/color]
                          >> works fine. So you[color=darkred]
                          >> >must have a bug somewhere.
                          >> >
                          >> >I hope those ideas help.
                          >> >
                          >> >"Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                          >> >news:075101c3b a87$c1f5f960$a0 01280a@phx.gbl. ..
                          >> >> I am extremely frustrated. I am building c#[/color]
                          >> application[color=darkred]
                          >> >> for a call center and am using a third party API to[/color]
                          >> access[color=darkred]
                          >> >> some hardware. When develop and test my class using[/color][/color][/color]
                          the[color=blue][color=green][color=darkred]
                          >> >> windows console the application runs flawlessly, but[/color]
                          >> once[color=darkred]
                          >> >> I call the class from inside a c# windows application[/color]
                          >> the[color=darkred]
                          >> >> program freezes, crashes etc...
                          >> >>
                          >> >> there must be a way to make this work inside a[/color][/color][/color]
                          windows[color=blue][color=green]
                          >> app[color=darkred]
                          >> >> as it run great as a command line app.
                          >> >>
                          >> >> Please any ideas would be welcomed at this trying[/color][/color][/color]
                          time[color=blue][color=green]
                          >> in[color=darkred]
                          >> >> my life
                          >> >>
                          >> >> Jim
                          >> >
                          >> >
                          >> >.
                          >> >[/color][/color]
                          >
                          >
                          >.
                          >[/color]

                          Comment

                          • Mountain Bikn' Guy

                            #14
                            Re: DllImport / unmanaged code


                            "Jim" <jenglish@natio nsfirstcorp.com > wrote in message
                            news:0cef01c3ba ce$dacfd9f0$a00 1280a@phx.gbl.. .[color=blue]
                            > Please I need more detail.
                            >[/color]

                            There are four methods on a control that are safe to call from any thread:
                            Invoke, BeginInvoke, EndInvoke, and CreateGraphics. For all other method
                            calls, you should use one of the invoke methods to marshal the call to the
                            control's thread.

                            You should also read this if you haven't already:
                            http://msdn.microsoft.com/library/de...ms06112002.asp

                            And Chris Sells's book, Windows Forms Programming in C# is great for
                            understanding this stuff.

                            Have you seen:
                            http://msdn.microsoft.com/library/de...ithvisualc.asp

                            and
                            http://msdn.microsoft.com/library/de...ml/vbasync.asp

                            Hope that helps.


                            Comment

                            • Mountain Bikn' Guy

                              #15
                              Re: DllImport / unmanaged code

                              there is a part 2 to Chris Sells's article:
                              http://msdn.microsoft.com/library/de...ms08162002.asp

                              [color=blue]
                              >
                              > You should also read this if you haven't already:
                              >[/color]
                              http://msdn.microsoft.com/library/de...ms06112002.asp[color=blue]
                              >[/color]



                              Comment

                              Working...