Dll method problem

Hi Guys
I am new bie in Windows mobile platform.
I am building a smartphone application using c#. It uses our own NetwrkAction.lib. Can you guys help me how can i use this lib in the project.
I have follwoing functions that has to be used in the application.

EXPORT CNetwrkAction* CALLBACK CreateNetwrkAction();
EXPORT void CALLBACK DeleteNetwrkAction(CNetwrkAction* obj);
EXPORT int CALLBACK Configure(CNetwrkAction* obj,LPVOID aErrorNotifier,LPVOID aEventNotifier, const char *aPrimaryGateway);
EXPORT int CALLBACK ConnectToServer(CNetwrkAction* obj);
EXPORT int CALLBACK RequestToServer(CNetwrkAction* obj,const char *aPrimaryGateway);

Can anybody tell me how to use this DLL with my program.




Answer this question

Dll method problem

  • balti bob

    Hi Ilya,

    I am stuck in the problem. I am not able to debug my dll. I searched forums but in the project property i am in cofguration i m not getting any debugger option.

    Is there any tool needs for this.

    thnx



  • Saurabh_Mathur

    You can't, not with C++ class. It needs to be either COM object or its needs to be a C structure.

    In first case you could use COM interop to access fields and methods, in second case you should declare its managed equivalent and pass it instead of IntPtr. I suppose you can try that with member variables for a class, but I can’t guarantee it would work.



  • DaveDB

    Please do not ask the same question several time. One thread is enough, merging...

    Also see this, item 15.



  • mipe10

    Thnx For reply. I will try to look in to it by using active debugger.

    Actually my concern is only that call back functions that i am passing on the function. Is it the right way to pass function

    thnx



  • chinmayv84

    thnx ilya

    it workd

    rg

    nb



  • Digital Mind

    Ilyaa,

    i have one more question.

    My EventNotify function definition is like EventNotify(int aid, void* aPtr ); the second param is a class that is defined in dll. How can i use that param

    thnx



  • j_o_h_a_n_n_e_s

    Hi Guys,

    Facing real problem with dll. I am using a dll with my project. I have to call a function of dll . The function is like this.

    EXPORT int CALLBACK Configure(CMyClient* obj,LPVOID apErrorNotifier,LPVOID apEventNotifier, const char *aPrimaryGateway, const char *aFallbackGateway, UINT aPort);

    where apErrorNotifier and apEventNotifier are the notifier functions that has be called when dll complete the process.

    apErrorNotifier and apEventNotifier is like

    void EventNotify(const TApplicationEvent aEventType, void *aData);

    void ErrorNotifier(const TApplicationEvent aEventType, void *aData);

    where TApplicationEvent is enum defined in dll.

    can anybody help me how to implement this on C#. I am wrking on smart phone.

    thnx



  • Meadensi

    Hi Ilya,

    i am again found myself in problem.

    I have to use the function of dll. that is like.

    EXPORT int CALLBACK Configure(CMyClient* obj,LPVOID apErrorNotifier,LPVOID apEventNotifier, const char *aPrimaryGateway,
    const char *aFallbackGateway, UINT aPort);

    here apErrorNotifierand and apEventNotifier are notifier function (Callback). The definition for these function is like this

    void EventNotify(const TApplicationEvent aEventType, void *aData);

    void ErrorNotify(const TApplicationEvent aEventType, void *aData);

    where TApplicationEvent is defined as enum in dll.

    How can i call configure function in the program. I am using C# for smrt devices.

    thnx



  • sidhuvirgoster

    Thnx Ilya for replying..

    I am sorry it is DLL.

    Once again thnx will let u know if found any problem

    thnx

    nb



  • DJMANCO

    Hi Ilya srry but i am really in trouble..

    Only the above mentioned Function is creating the problem. All other functions that i am caling are working fine. I have gone thru several links and changed my code for callback implementation. here is the code that i am using now.

    NOTE: dll is build for Smart Phone

    namespace SplashScreen

    {

    public delegate void ErrorNotify(int anotify, IntPtr data);

    public delegate void EventNotify(int anotify, IntPtr data);

    public partial class Form1 : Form

    {

    //IVeClient* pVeClient = null;

    public IntPtr pMyClient;

    public static void ErrorNotify(int anotify, IntPtr data)

    {

    switch (anotify)

    {

    case 1:

    case 2:

    default:

    break;

    }

    }

    public static void EventNotify(int anotify, IntPtr data)

    {

    switch (anotify)

    {

    case 1:

    case 2:

    default:

    break;

    }

    }

    public class VeClientInterface

    {

    #region DLLImports

    [DllImport("VeClient.dll")]

    public static extern IntPtr CreateVeClient();

    /*

    [DllImport("VeClient.dll",CallingConvention=CallingConvention.Winapi)]

    public static extern int Configure(IntPtr pVe, ErrorNotify apErrorNotifier, EventNotify apEventNotifier,

    [MarshalAs(UnmanagedType.LPStr)] string aPrimaryGateway,

    [MarshalAs(UnmanagedType.LPStr)] string aFallbackGateway, uint aPort,

    [MarshalAs(UnmanagedType.LPStr)] string aDeviceId,

    [MarshalAs(UnmanagedType.LPStr)] string aPhoneNum,

    [MarshalAs(UnmanagedType.LPStr)] string aDevelopId,

    [MarshalAs(UnmanagedType.LPStr)] string aPin,

    [MarshalAs(UnmanagedType.LPStr)] string aAppName,

    [MarshalAs(UnmanagedType.LPStr)] string aAppId);

    */

    [DllImport("VeClient.dll")]

    public static extern int Configure(IntPtr pVe, ErrorNotify apErrorNotifier, EventNotify apEventNotifier,

    string aPrimaryGateway,

    string aFallbackGateway, uint aPort,

    string aDeviceId,

    string aPhoneNum,

    string aDevelopId,

    string aPin,

    string aAppName,

    string aAppId);

    [DllImport("VeClient.dll")]

    public static extern int StartSession(IntPtr obj);

    /*

    [DllImport("VeClient.dll")]

    public static extern void AddMileage(IntPtr aManager, string aDescription, int aMiles);

    [DllImport("VeClient.dll")]

    public static extern bool GetNextRecord(IntPtr aManager, StringBuilder aDescription, ref int aMiles);

    [DllImport("VeClient.dll")]

    public static extern void ClearMileage(IntPtr aManager);

    */

    #endregion //DLLImports

    }

    public Form1()

    {

    int nret = 0;

    //VeClientInterface pVeCl;// = new VeClientInterface();

    pVeClient = VeClientInterface.CreateVeClient();

    /*VeClientInterface.Configure(pVeClient, ErrorNotify, EventNotify, "216.98.159.238", "216.98.159.238", 443, "1101",

    "9818667066", "011", "123", "MYWIDGET", "100");

    */

    EventNotify appEvtNotify = new EventNotify(Form1.EventNotify);

    ErrorNotify appErrNotify = new ErrorNotify(Form1.EventNotify);

    nret = VeClientInterface.Configure(this.pVeClient, appErrNotify, appEvtNotify, "216.98.159.233", "216.98.159.233", 443, "1101",

    "9818667066", "011", "123", "MYWIDGET", "100");

    nret = VeClientInterface.StartSession(this.pVeClient);

    InitializeComponent();

    }

    }



  • lostromich

    Sorry, I can't help you as you're keeping it a secret on how exactly it does not work.

    One thing I've noticed your native strings are declared as 8 bit ANSI strings:

    const char *aPrimaryGateway, const char *aFallbackGatewayconst char *aPrimaryGateway

    Since Windows CE/Mobile uses Unicode for everything you could not do that since strings would be passed as 16 bit unicode:

    nret = VeClientInterface.Configure(this.pVeClient, appErrNotify, appEvtNotify, "216.98.159.233", "216.98.159.233", 443, "1101"

    Either change your DLL to accept Unicode strings or make sure you're passing 8 bit strings, e.g. by using Encoding.GetBytes() and passing byte arrays instead of strings.

    I would also suggest attaching native debugger to the DLL to make sure all arguments are arriving as expected.



  • Morten Nielsen

    Here's a classic example of call back if you have doubts in your own implementation: http://pinvoke.net/default.aspx/user32/EnumWindows.html



  • chaza

    You have to declare managed equivalents of all types used in these, declare managed delegates for native call backs and then you'd need to declare P/Invokes themselves. For that you would need to examine native side declarations, see links above for details.

    Before you even start on that endeavor (and it might be quite tricky), I suggest making sure this DLL is compiled for device. Here’s the simple rule: if this DLL works on desktop you can NOT use it on device. It needs to be ported and recompiled first.

    You might also debug your declarations on desktop and then move them to device.



  • planetmarshalluk

    You're sending rather confliction messages here. Do you have LIB or do you have DLL They are quite different -you can not use LIB from C# unless you link it to some code which would expose the functionality as a DLL. If it's a DLL, you should P/Invoke into it from C# code (assuming it's compiled for device). See this and this.



  • Dll method problem