Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Function getHandle() throughs a stack overflow exception. I cannot detect any recursion. any ideas why this could happen?
Details: The dll file is available to my code. Function init(dllName)is called first to get the handle and check to see if the dll entries return true (if the address exist).

C#
class BTS200
{
    [DllImport("GOMDBTS200.dll", EntryPoint = "GOMDBTS200_getHandle")]
    private static extern int getHandle(string device_Name, ref int _handle);

    [DllImport("GOMDBTS200.dll", EntryPoint = "GOMDBTS200_showConfig")]
    private static extern int showConfig(ref int applicationHandle, int controlBits);

    [DllImport("GOMDBTS200.dll", EntryPoint = "GOMDBTS200_getProcAddresses")]
    private static extern bool getProcAddresses(ref int p_hLibrary, string p_dllName, int p_count);



    static private bool hreleaseHandle;
    static private bool hshowConfig;
    string deviceName = "BTS200_1234";
    int handle = -1;

    public int init(string dll)
    {
        _getHandle();

        if (handle == 0)
            return 0;
        else
        {
            hreleaseHandle = getProcAddresses(ref handle, "GOMDBTS200_releaseHandle", 1);
            hshowConfig = getProcAddresses(ref handle, "GOMDBTS200_showConfig", 1);
        }
        return 0;
    }



    public int _getHandle()
    {
        getHandle(deviceName, ref handle);
        return 0;
    }

    public int _showConfig()
    {
        if (hshowConfig == true)
        {
            showConfig(ref handle, 0);
        }
        return 0;
    }

}
Posted
Comments
Sergey Alexandrovich Kryukov 3-Dec-13 20:47pm    
Not enough information, because we cannot see implementation of GOMDBTS200_getHandle.
—SA
Member 8456258 3-Dec-13 20:59pm    
The implementation of GOMBTS200_getHandle is not available to me since it is within the dll provided with the instrument. All I know is the entry name, which is just that. Do you think recursion happens there?
Sergey Alexandrovich Kryukov 3-Dec-13 22:19pm    
Not sure, but it looks so from your information. You can easily check it up with the debugger. Set the break point on the beginning of the implementation of _getHandle. It it stops there again, look at call stack.
—SA
Member 8456258 13-Jan-14 17:17pm    
If I compile with debuging option (in VS2010) a recursion happens somewhere (stack overflow exception). But when I run without debug the code compiles and runs just fine. I am wondering if it is because teh fact the variable "handle" is referenced or somethign else.
Sergey Alexandrovich Kryukov 14-Jan-14 2:02am    
Call stack windows shows you where the calls some from...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900