Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to call the function in cellcore.dll?

How to call the function in cellcore.dll?

Scheduled Pinned Locked Moved C#
tutorialhostingcloudhelpquestion
23 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W whiteclouds

    I am pleasure to see your answer. Thank you! But I have still a problem. As the code you show, the struct LINEINITIALIZEEXPARAMS has two elements: hEvent and hCompletionPort. But in C++, this struct has a union. The element in it have the same name as your code. I know the keyword "union" isn't exist in C#. But I think this struct shouldn't be declare as this. Additional, I can't still execute this program. The error is still "No entry point found for lineInitializeEx". I hope you can help me again. Thx!

    There is some white cloud floating on the blue sky. That's the landscape I like.

    D Offline
    D Offline
    DaveyM69
    wrote on last edited by
    #6

    According to P/Invoke.net, lineInitializeEx is in coredll.dll NOT cellcore.dll

    Dave
    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

    W 1 Reply Last reply
    0
    • D DaveyM69

      According to P/Invoke.net, lineInitializeEx is in coredll.dll NOT cellcore.dll

      Dave
      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      W Offline
      W Offline
      whiteclouds
      wrote on last edited by
      #7

      Yes, you are right. I had success to execute it now. Thank you very much! :laugh:

      There is some white cloud floating on the blue sky. That's the landscape I like.

      1 Reply Last reply
      0
      • D DaveyM69

        You are correct about the struct - I missed the union :doh:

        [StructLayout(LayoutKind.Explict)]
        private struct LINEINITIALIZEEXPARAMS
        {
        [FieldOffset(0)]
        public uint dwTotalSize;
        [FieldOffset(4)]
        public uint dwNeededSize;
        [FieldOffset(8)]
        public uint dwUsedSize;
        [FieldOffset(12)]
        public IntPtr hEvent;
        public IntPtr hCompletionPort;
        [FieldOffset(12)]
        public uint dwCompletionKey;
        }

        Are you sure you have the dll installed as it seems windows can't find it? If it's on your system, try using an absolute path.

        Dave
        Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #8

        Excellent thread, except:

        DaveyM69 wrote:

        [FieldOffset(12)] public uint dwCompletionKey;

        IMO it is either 16 (Win32) or 20 (Win64). :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        D 1 Reply Last reply
        0
        • L Luc Pattyn

          Excellent thread, except:

          DaveyM69 wrote:

          [FieldOffset(12)] public uint dwCompletionKey;

          IMO it is either 16 (Win32) or 20 (Win64). :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #9

          I'm never 100% sure about unions not being a C guy. I believe that at byte 12 will be either hEvent OR dwCompletionKey. The way I understand it is that if the handles aren't used then the size of the struct will be 16 bytes, if the handles aren't are used, then the size will be 20 bytes if Win32 or 28 if Win64. The location of dwCompletionKey/hEvent will always be 12 and only the size of the struct will be different. Please correct me if I'm wrong!

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          L 1 Reply Last reply
          0
          • D DaveyM69

            I'm never 100% sure about unions not being a C guy. I believe that at byte 12 will be either hEvent OR dwCompletionKey. The way I understand it is that if the handles aren't used then the size of the struct will be 16 bytes, if the handles aren't are used, then the size will be 20 bytes if Win32 or 28 if Win64. The location of dwCompletionKey/hEvent will always be 12 and only the size of the struct will be different. Please correct me if I'm wrong!

            Dave
            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #10

            Hi Dave, This is the original definition from MSDN:

            typedef struct lineinitializeexparams_tag {
            DWORD dwTotalSize;
            DWORD dwNeededSize;
            DWORD dwUsedSize;
            DWORD dwOptions;
            union {
            HANDLE hEvent;
            HANDLE hCompletionPort;
            } Handles;
            DWORD dwCompletionKey;
            } LINEINITIALIZEEXPARAMS, *LPLINEINITIALIZEEXPARAMS;

            in C/C++ every struct member that is not inside a union block will be layed out sequentially; and everything inside a union block will share the same memory (and needs the size of the largest item), so here hEvent and hCompletionPort are overlapping, however dwCompletionKey (not being part of the union) must be at the next suitable address following the union, hence at start of union item plus 4 ot 8 depending on pointer sizes. BTW: there seems to be a dwOptions member too, which hasn't been mentioned before! :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            D 1 Reply Last reply
            0
            • L Luc Pattyn

              Hi Dave, This is the original definition from MSDN:

              typedef struct lineinitializeexparams_tag {
              DWORD dwTotalSize;
              DWORD dwNeededSize;
              DWORD dwUsedSize;
              DWORD dwOptions;
              union {
              HANDLE hEvent;
              HANDLE hCompletionPort;
              } Handles;
              DWORD dwCompletionKey;
              } LINEINITIALIZEEXPARAMS, *LPLINEINITIALIZEEXPARAMS;

              in C/C++ every struct member that is not inside a union block will be layed out sequentially; and everything inside a union block will share the same memory (and needs the size of the largest item), so here hEvent and hCompletionPort are overlapping, however dwCompletionKey (not being part of the union) must be at the next suitable address following the union, hence at start of union item plus 4 ot 8 depending on pointer sizes. BTW: there seems to be a dwOptions member too, which hasn't been mentioned before! :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #11

              Hmm... intersting. The only time I've written code requiring it was for MMTIME[^] which I have like this :confused:

              /* http://msdn.microsoft.com/en-us/library/dd757347(v=VS.85).aspx
              typedef struct mmtime_tag {
              UINT wType;
              union {
              DWORD ms;
              DWORD sample;
              DWORD cb;
              DWORD ticks;
              struct {
              BYTE hour;
              BYTE min;
              BYTE sec;
              BYTE frame;
              BYTE fps;
              BYTE dummy;
              BYTE pad[2];
              } smpte;
              struct {
              DWORD songptrpos;
              } midi;
              } u;
              } MMTIME, *PMMTIME, *LPMMTIME; */
              /// <summary>
              /// Contains timing information for different types of multimedia data.
              /// </summary>
              [StructLayout(LayoutKind.Explicit)]
              internal struct MMTIME
              {
              /// <summary>
              /// Time format.
              /// </summary>
              [FieldOffset(0)]
              public uint wType;
              /// <summary>
              /// Number of milliseconds.
              /// Used when wType is TIME_MS.
              /// </summary>
              [FieldOffset(4)]
              public uint ms;
              /// <summary>
              /// Number of samples.
              /// Used when wType is TIME_SAMPLES.
              /// </summary>
              [FieldOffset(4)]
              public uint sample;
              /// <summary>
              /// Byte count.
              /// Used when wType is TIME_BYTES.
              /// </summary>
              [FieldOffset(4)]
              public uint cb;
              /// <summary>
              /// Ticks in MIDI stream.
              /// Used when wType is TIME_TICKS.
              /// </summary>
              [FieldOffset(4)]
              public uint ticks;
              /// <summary>
              /// Hours.
              /// Used when wType is TIME_SMPTE.
              /// </summary>
              [FieldOffset(4)]
              public byte hour;
              /// <summary>
              /// Minutes.
              /// Used when wType is TIME_SMPTE.
              /// </summary>
              [FieldOffset(5)]
              public byte min;
              /// <summary>
              /// Seconds.
              /// Used when wType is TIME_SMPTE.
              /// </summar

              L 1 Reply Last reply
              0
              • D DaveyM69

                Hmm... intersting. The only time I've written code requiring it was for MMTIME[^] which I have like this :confused:

                /* http://msdn.microsoft.com/en-us/library/dd757347(v=VS.85).aspx
                typedef struct mmtime_tag {
                UINT wType;
                union {
                DWORD ms;
                DWORD sample;
                DWORD cb;
                DWORD ticks;
                struct {
                BYTE hour;
                BYTE min;
                BYTE sec;
                BYTE frame;
                BYTE fps;
                BYTE dummy;
                BYTE pad[2];
                } smpte;
                struct {
                DWORD songptrpos;
                } midi;
                } u;
                } MMTIME, *PMMTIME, *LPMMTIME; */
                /// <summary>
                /// Contains timing information for different types of multimedia data.
                /// </summary>
                [StructLayout(LayoutKind.Explicit)]
                internal struct MMTIME
                {
                /// <summary>
                /// Time format.
                /// </summary>
                [FieldOffset(0)]
                public uint wType;
                /// <summary>
                /// Number of milliseconds.
                /// Used when wType is TIME_MS.
                /// </summary>
                [FieldOffset(4)]
                public uint ms;
                /// <summary>
                /// Number of samples.
                /// Used when wType is TIME_SAMPLES.
                /// </summary>
                [FieldOffset(4)]
                public uint sample;
                /// <summary>
                /// Byte count.
                /// Used when wType is TIME_BYTES.
                /// </summary>
                [FieldOffset(4)]
                public uint cb;
                /// <summary>
                /// Ticks in MIDI stream.
                /// Used when wType is TIME_TICKS.
                /// </summary>
                [FieldOffset(4)]
                public uint ticks;
                /// <summary>
                /// Hours.
                /// Used when wType is TIME_SMPTE.
                /// </summary>
                [FieldOffset(4)]
                public byte hour;
                /// <summary>
                /// Minutes.
                /// Used when wType is TIME_SMPTE.
                /// </summary>
                [FieldOffset(5)]
                public byte min;
                /// <summary>
                /// Seconds.
                /// Used when wType is TIME_SMPTE.
                /// </summar

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #12

                That looks OK; there is one union, all its members are starting at the same offset (4), and nothing is following the union (both inner structs are inside the union, the union is the last member of the outer struct). :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                D 1 Reply Last reply
                0
                • L Luc Pattyn

                  That looks OK; there is one union, all its members are starting at the same offset (4), and nothing is following the union (both inner structs are inside the union, the union is the last member of the outer struct). :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  D Offline
                  D Offline
                  DaveyM69
                  wrote on last edited by
                  #13

                  :thumbsup:

                  Dave
                  Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                  1 Reply Last reply
                  0
                  • W whiteclouds

                    I am pleasure to see your answer. Thank you! But I have still a problem. As the code you show, the struct LINEINITIALIZEEXPARAMS has two elements: hEvent and hCompletionPort. But in C++, this struct has a union. The element in it have the same name as your code. I know the keyword "union" isn't exist in C#. But I think this struct shouldn't be declare as this. Additional, I can't still execute this program. The error is still "No entry point found for lineInitializeEx". I hope you can help me again. Thx!

                    There is some white cloud floating on the blue sky. That's the landscape I like.

                    D Offline
                    D Offline
                    DaveyM69
                    wrote on last edited by
                    #14

                    Following the discussion I had with Luc, I've done some investigation into the way uinions work, and he is correct, the parameters inside the union block start at the same place in memory - in otherwords, the struct will contain one of the handles but not both so the best way to declare it is:

                    [StructLayout(LayoutKind.Sequential)]
                    private struct LINEINITIALIZEEXPARAMS
                    {
                    public uint dwTotalSize;
                    public uint dwNeededSize;
                    public uint dwUsedSize;
                    public uint dwOptions;
                    public IntPtr handle; // Will be either hEvent OR hCompletionPort
                    public uint dwCompletionKey;
                    }

                    Dave
                    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                    W 1 Reply Last reply
                    0
                    • D DaveyM69

                      Following the discussion I had with Luc, I've done some investigation into the way uinions work, and he is correct, the parameters inside the union block start at the same place in memory - in otherwords, the struct will contain one of the handles but not both so the best way to declare it is:

                      [StructLayout(LayoutKind.Sequential)]
                      private struct LINEINITIALIZEEXPARAMS
                      {
                      public uint dwTotalSize;
                      public uint dwNeededSize;
                      public uint dwUsedSize;
                      public uint dwOptions;
                      public IntPtr handle; // Will be either hEvent OR hCompletionPort
                      public uint dwCompletionKey;
                      }

                      Dave
                      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                      W Offline
                      W Offline
                      whiteclouds
                      wrote on last edited by
                      #15

                      I'm glad to see your answer. But now I meet a new problem, that I can't get HINSTANCE. I had find some ways in MSDN. But no available way I found. Could you be kind to help me again? Thank you! :)

                      There is some white cloud floating on the blue sky. That's the landscape I like.

                      modified on Monday, September 13, 2010 2:03 AM

                      D 1 Reply Last reply
                      0
                      • W whiteclouds

                        I'm glad to see your answer. But now I meet a new problem, that I can't get HINSTANCE. I had find some ways in MSDN. But no available way I found. Could you be kind to help me again? Thank you! :)

                        There is some white cloud floating on the blue sky. That's the landscape I like.

                        modified on Monday, September 13, 2010 2:03 AM

                        D Offline
                        D Offline
                        DaveyM69
                        wrote on last edited by
                        #16

                        MSDN says: "Instance handle of the client application or DLL. The application or DLL can pass NULL for this parameter, in which case TAPI uses the module handle of the root executable of the process (for purposes of identifying call handoff targets and media mode priorities). The clue is "can pass NULL", which in the case of PInvoke handles is IntPtr.Zero. That should work. If not, have a look at the Process.Handle[^] property - perhaps this will work?

                        IntPtr hInstance = System.Diagnostics.Process.GetCurrentProcess().Handle;

                        and pass hInstance as the parameter..., I prefer IntPtr.Zero though!

                        Dave
                        Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                        W 1 Reply Last reply
                        0
                        • D DaveyM69

                          MSDN says: "Instance handle of the client application or DLL. The application or DLL can pass NULL for this parameter, in which case TAPI uses the module handle of the root executable of the process (for purposes of identifying call handoff targets and media mode priorities). The clue is "can pass NULL", which in the case of PInvoke handles is IntPtr.Zero. That should work. If not, have a look at the Process.Handle[^] property - perhaps this will work?

                          IntPtr hInstance = System.Diagnostics.Process.GetCurrentProcess().Handle;

                          and pass hInstance as the parameter..., I prefer IntPtr.Zero though!

                          Dave
                          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                          W Offline
                          W Offline
                          whiteclouds
                          wrote on last edited by
                          #17

                          I had tested the code above. I feel sorry that it can't work. Because I am developing application for Windows Mobile. The property System.Diagnostics.Process.GetCurrentProcess().Handle can't be get in Mobile. I had try to give hInstance with the value of new IntPtr(GetModuleHandle(new IntPtr(0)).ToInt32()). But when I call lineInitializeEx with it, the return value is an error code. That tell me the value of handle is invalid(0x80000035). Base of all, I think I can't call lineInitializeEx with C# at all. Isn't it?

                          There is some white cloud floating on the blue sky. That's the landscape I like.

                          D 1 Reply Last reply
                          0
                          • W whiteclouds

                            I had tested the code above. I feel sorry that it can't work. Because I am developing application for Windows Mobile. The property System.Diagnostics.Process.GetCurrentProcess().Handle can't be get in Mobile. I had try to give hInstance with the value of new IntPtr(GetModuleHandle(new IntPtr(0)).ToInt32()). But when I call lineInitializeEx with it, the return value is an error code. That tell me the value of handle is invalid(0x80000035). Base of all, I think I can't call lineInitializeEx with C# at all. Isn't it?

                            There is some white cloud floating on the blue sky. That's the landscape I like.

                            D Offline
                            D Offline
                            DaveyM69
                            wrote on last edited by
                            #18

                            Have you tried with IntPtr.Zero or new IntPtr(0) What is the error code? It should be one of these:

                            /// <summary>
                            /// No error.
                            /// </summary>
                            public const uint LINEERR\_NOERROR = 0x00000000;
                            /// <summary>
                            /// Invalid application name.
                            /// </summary>
                            public const uint LINEERR\_INVALAPPNAME = 0x80000015;
                            /// <summary>
                            /// The INI file is corrupted.
                            /// </summary>
                            public const uint LINEERR\_INIFILECORRUPT = 0x8000000E;
                            /// <summary>
                            /// Invalid parameter.
                            /// </summary>
                            public const uint LINEERR\_INVALPARAM = 0x80000032;
                            /// <summary>
                            /// Invalid pointer.
                            /// </summary>
                            public const uint LINEERR\_INVALPOINTER = 0x80000035;
                            /// <summary>
                            /// No memory available.
                            /// </summary>
                            public const uint LINEERR\_NOMEM = 0x80000044;
                            /// <summary>
                            /// The operation failed.
                            /// </summary>
                            public const uint LINEERR\_OPERATIONFAILED = 0x80000048;
                            /// <summary>
                            /// The application attempted to initialize TAPI twice.
                            /// </summary>
                            public const uint LINEERR\_REINIT = 0x80000052;
                            

                            If the version of WinMob you're targetting supports TAPI then it will work once you get it just right! Maybe post your lineInitializeEx and LINEINITIALIZEEXPARAMS...

                            Dave
                            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                            W 1 Reply Last reply
                            0
                            • D DaveyM69

                              Have you tried with IntPtr.Zero or new IntPtr(0) What is the error code? It should be one of these:

                              /// <summary>
                              /// No error.
                              /// </summary>
                              public const uint LINEERR\_NOERROR = 0x00000000;
                              /// <summary>
                              /// Invalid application name.
                              /// </summary>
                              public const uint LINEERR\_INVALAPPNAME = 0x80000015;
                              /// <summary>
                              /// The INI file is corrupted.
                              /// </summary>
                              public const uint LINEERR\_INIFILECORRUPT = 0x8000000E;
                              /// <summary>
                              /// Invalid parameter.
                              /// </summary>
                              public const uint LINEERR\_INVALPARAM = 0x80000032;
                              /// <summary>
                              /// Invalid pointer.
                              /// </summary>
                              public const uint LINEERR\_INVALPOINTER = 0x80000035;
                              /// <summary>
                              /// No memory available.
                              /// </summary>
                              public const uint LINEERR\_NOMEM = 0x80000044;
                              /// <summary>
                              /// The operation failed.
                              /// </summary>
                              public const uint LINEERR\_OPERATIONFAILED = 0x80000048;
                              /// <summary>
                              /// The application attempted to initialize TAPI twice.
                              /// </summary>
                              public const uint LINEERR\_REINIT = 0x80000052;
                              

                              If the version of WinMob you're targetting supports TAPI then it will work once you get it just right! Maybe post your lineInitializeEx and LINEINITIALIZEEXPARAMS...

                              Dave
                              Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                              W Offline
                              W Offline
                              whiteclouds
                              wrote on last edited by
                              #19

                              I had try to use the value of IntPtr.Zero and new IntPtr(0) before. The return value is error too. In all cases, the error code returned is still public const uint LINEERR_INVALPOINTER = 0x80000035;. I am sure my Window Mobile support TAPI. I had developed a TAPI application with C++. Thank you!

                              There is some white cloud floating on the blue sky. That's the landscape I like.

                              D 1 Reply Last reply
                              0
                              • W whiteclouds

                                I had try to use the value of IntPtr.Zero and new IntPtr(0) before. The return value is error too. In all cases, the error code returned is still public const uint LINEERR_INVALPOINTER = 0x80000035;. I am sure my Window Mobile support TAPI. I had developed a TAPI application with C++. Thank you!

                                There is some white cloud floating on the blue sky. That's the landscape I like.

                                D Offline
                                D Offline
                                DaveyM69
                                wrote on last edited by
                                #20

                                Can you post your function and struct declarations?

                                Dave
                                Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                                W 1 Reply Last reply
                                0
                                • D DaveyM69

                                  Can you post your function and struct declarations?

                                  Dave
                                  Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                                  W Offline
                                  W Offline
                                  whiteclouds
                                  wrote on last edited by
                                  #21
                                      public bool OpenLine()
                                      {
                                          UInt32 dwDevNum = 0;//count the devices
                                          UInt32 dwApiVerSion = TAPI\_CURRENT\_VERSION;
                                          LINEINITIALIZEEXPARAMS dtParams = new LINEINITIALIZEEXPARAMS();
                                          dtParams.dwTotalSize = (UInt32)Marshal.SizeOf(dtParams);
                                          dtParams.dwOptions = 1;
                                          IntPtr handles = new IntPtr(0);
                                  
                                          IntPtr hInstance = IntPtr.Zero;//new IntPtr(GetModuleHandle(new IntPtr(0)).ToInt32());
                                          unsafe
                                          {
                                              fixed(IntPtr \*hLineApp = &m\_hLineApp)
                                              {
                                                  long lResult = lineInitializeEx(hLineApp, hInstance, new IntPtr(0), new IntPtr(0),
                                                      new IntPtr(&dwDevNum), new IntPtr(&dwApiVerSion), new IntPtr(&dtParams));
                                                  if (lResult == 0)
                                                  {
                                                      return true;
                                                  }
                                              }
                                              return false;
                                          }
                                      }
                                      \[StructLayout(LayoutKind.Sequential)\]
                                      private struct LINEINITIALIZEEXPARAMS
                                      {
                                          public uint dwTotalSize;
                                          public uint dwNeededSize;
                                          public uint dwUsedSize;
                                          public uint dwOptions;
                                          public IntPtr hMultiUse;  
                                          public uint dwCompletionKey;
                                      }
                                      \[DllImport("coredll.dll", SetLastError = true)\]
                                      unsafe private static extern uint lineInitializeEx(
                                          IntPtr \*lphLineApp,
                                          IntPtr hInstance,
                                          IntPtr pfnCallback,//lineCallbackFunc lpfnCallback,
                                          IntPtr FriendAppName,//StringBuilder lpszFriendlyAppName,
                                          IntPtr pNumDevs,//out uint lpdwNumDevs,
                                          IntPtr pAPIVersion,//out uint lpdwAPIVersion,
                                          IntPtr pLineInitializeExParams);//ref LINEINITIALIZEEXPARAMS lpLineInitializeExParams);
                                  

                                  There is some white cloud floating on the blue sky. That's the landscape I like.

                                  D 1 Reply Last reply
                                  0
                                  • W whiteclouds
                                        public bool OpenLine()
                                        {
                                            UInt32 dwDevNum = 0;//count the devices
                                            UInt32 dwApiVerSion = TAPI\_CURRENT\_VERSION;
                                            LINEINITIALIZEEXPARAMS dtParams = new LINEINITIALIZEEXPARAMS();
                                            dtParams.dwTotalSize = (UInt32)Marshal.SizeOf(dtParams);
                                            dtParams.dwOptions = 1;
                                            IntPtr handles = new IntPtr(0);
                                    
                                            IntPtr hInstance = IntPtr.Zero;//new IntPtr(GetModuleHandle(new IntPtr(0)).ToInt32());
                                            unsafe
                                            {
                                                fixed(IntPtr \*hLineApp = &m\_hLineApp)
                                                {
                                                    long lResult = lineInitializeEx(hLineApp, hInstance, new IntPtr(0), new IntPtr(0),
                                                        new IntPtr(&dwDevNum), new IntPtr(&dwApiVerSion), new IntPtr(&dtParams));
                                                    if (lResult == 0)
                                                    {
                                                        return true;
                                                    }
                                                }
                                                return false;
                                            }
                                        }
                                        \[StructLayout(LayoutKind.Sequential)\]
                                        private struct LINEINITIALIZEEXPARAMS
                                        {
                                            public uint dwTotalSize;
                                            public uint dwNeededSize;
                                            public uint dwUsedSize;
                                            public uint dwOptions;
                                            public IntPtr hMultiUse;  
                                            public uint dwCompletionKey;
                                        }
                                        \[DllImport("coredll.dll", SetLastError = true)\]
                                        unsafe private static extern uint lineInitializeEx(
                                            IntPtr \*lphLineApp,
                                            IntPtr hInstance,
                                            IntPtr pfnCallback,//lineCallbackFunc lpfnCallback,
                                            IntPtr FriendAppName,//StringBuilder lpszFriendlyAppName,
                                            IntPtr pNumDevs,//out uint lpdwNumDevs,
                                            IntPtr pAPIVersion,//out uint lpdwAPIVersion,
                                            IntPtr pLineInitializeExParams);//ref LINEINITIALIZEEXPARAMS lpLineInitializeExParams);
                                    

                                    There is some white cloud floating on the blue sky. That's the landscape I like.

                                    D Offline
                                    D Offline
                                    DaveyM69
                                    wrote on last edited by
                                    #22

                                    Not too sure where the problem is. The first thing I'd do is get rid of the *, &, unsafe and fixed pointer stuff. It's rarely needed as the built in marshaller can handle this stuff way better. I doubt it's the cause of your problems but declaring dwDevNum and creating a pointer from it's address is not going to work. There are two keywords for passing value types by reference (thier pointer), ref and out. If a value needs to be passed into a function then use ref. If the function doesn't need a value but there will be one there after the function returns then use out. In the case of dwDevNum this should be out but lpdwAPIVersion and dtParams should be ref. As IntPtr is a value type the pointer to a pointer for lphLineApp can be done using ref/out as well. To the solution... have a look at this[^]. The guy says his C# code works.

                                    Dave
                                    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                                    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                                    W 1 Reply Last reply
                                    0
                                    • D DaveyM69

                                      Not too sure where the problem is. The first thing I'd do is get rid of the *, &, unsafe and fixed pointer stuff. It's rarely needed as the built in marshaller can handle this stuff way better. I doubt it's the cause of your problems but declaring dwDevNum and creating a pointer from it's address is not going to work. There are two keywords for passing value types by reference (thier pointer), ref and out. If a value needs to be passed into a function then use ref. If the function doesn't need a value but there will be one there after the function returns then use out. In the case of dwDevNum this should be out but lpdwAPIVersion and dtParams should be ref. As IntPtr is a value type the pointer to a pointer for lphLineApp can be done using ref/out as well. To the solution... have a look at this[^]. The guy says his C# code works.

                                      Dave
                                      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
                                      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                                      W Offline
                                      W Offline
                                      whiteclouds
                                      wrote on last edited by
                                      #23

                                      I will study the code you provided. Thank you!

                                      There is some white cloud floating on the blue sky. That's the landscape I like.

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups