EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: explicit dynamic linking and ca.dll . CA bug?
From: "Jeff Hill" <[email protected]>
To: "'Liyu, Andrei'" <[email protected]>, <[email protected]>
Date: Tue, 28 Sep 2004 10:40:21 -0600
Liyu,

I did some additional research debunking my theory related to "thunks".

My new theory is that your program segmentation faults because it has bugs
in it (I am actually quite familiar with this theory due to personal
experience with my own code by the way). The following is an example of at
least one spot where you might take another look.

> //	piFca_clear_channel = ( iFca_clear_channel) GetProcAddress(
> hLibrary, "_ca_pend_io@4");
> //	if( piFca_clear_channel != NULL)

I attached a similar short program which works fine here.

PS: I still maintain that it will be much easier to use ordinary implicit
linking in your CA to labView shim DLL.

Jeff

> -----Original Message-----
> From: Jeff Hill [mailto:[email protected]]
> Sent: Monday, September 27, 2004 1:43 PM
> To: 'Liyu, Andrei'; '[email protected]'
> Subject: RE: explicit dynamic linking and ca.dll . CA bug?
> 
> 
> Liyu,
> 
> I am confused about why you appear to have labView explicitly linking
> with ca.dll. It seems that a person would write a special shim dll for
> interfacing labView with CA and have labview explicitly link with *that*
> dll's interface instead of with ca.dll's interface? The shim DLL would
> then implicitly link with ca.dll. That should be an easier approach. I
> assume that this has already been done by other folks?
> 
> In any case, my very wild guess is that your troubles might occur
> because the DLL's "thunk" (a code stub that transfers control to the
> function) is used rather than the address of the function. This may be
> because "dllimport" was used in shareLib.h.
> 
> Jeff
> 
> 
> > -----Original Message-----
> > From: Liyu, Andrei [mailto:[email protected]]
> > Sent: Monday, September 27, 2004 11:59 AM
> > To: [email protected]
> > Subject: explicit dynamic linking and ca.dll . CA bug?
> >
> > Hi,
> >
> > 	Some months ago I wrote Jeff that I still have problem with
> > LabView's library to CA client. When LabView program finishes to work
> > with CA (=calls ca_context_destroy() ) I see that LabView crashed.
> When
> > I start from Visual C++ debug I see message
> > "First-chance exception in LabView.exe (NTDLL.DLL): 0xC0000005: Access
> > Violation."
> > 	In that case it was difficult to catch bug. It could be in
> > LabView, in library, in Epics CA. Moreover, other simple tests work
> > fine.
> > 	Some days ago I noticed difference between LabView call and
> > simple test programs. My simple test programs call ca.dll in "Implicit
> > dynamic linking". LabView calls any dll in "Explicit dynamic linking".
> >
> > 	I wrote the simplest program
> > ============================
> > #include <windows.h>
> > #include "cadef.h"
> >
> > HINSTANCE hLibrary;
> >
> > char * AcPVName = "DTL_Diag:ND334:FaLoss1";
> > chid chidChannelToPV;
> >
> > typedef int ( __stdcall * iFca_context_create)( enum);
> > iFca_context_create piFca_context_create;
> >
> > //epicsShareFunc int epicsShareAPI ca_create_channel( const char
> > *pChanName,
> > //		caCh *pConnStateCallback, void *pUserPrivate, capri
> > priority, chid *pChanID);
> > typedef int ( __stdcall * iFca_create_channel)( const char *, caCh *,
> > void *, capri, chid *);
> > iFca_create_channel piFca_create_channel;
> >
> > //epicsShareFunc int epicsShareAPI ca_pend_io( ca_real timeOut);
> > typedef int ( __stdcall * iFca_pend_io)( ca_real timeOut);
> > iFca_pend_io piFca_pend_io;
> >
> > //epicsShareFunc int epicsShareAPI ca_clear_channel( chid chanId);
> > typedef int ( __stdcall * iFca_clear_channel)( chid chanId);
> > iFca_clear_channel piFca_clear_channel;
> >
> > typedef int ( __stdcall * iFca_context_destroy)( void);
> > iFca_context_destroy piFca_context_destroy;
> >
> > typedef int ( __stdcall * iFca_context_destroy)( void);
> > iFca_context_destroy piFca_context_destroy;
> >
> > int main(){
> > 	long lStatus;
> > 	hLibrary = LoadLibrary("C:\\Epics\\bin\\win32-x86\\ca.dll");
> >
> > 	piFca_context_create = ( iFca_context_create) GetProcAddress(
> > hLibrary, "_ca_context_create@4");
> > 	if( piFca_context_create != NULL)
> > 		lStatus = ( ( piFca_context_create)(
> > ca_enable_preemptive_callback));
> >
> > //	piFca_create_channel = ( iFca_create_channel) GetProcAddress(
> > hLibrary, "_ca_create_channel@20");
> > //	if( piFca_create_channel != NULL)
> > //		lStatus = ( ( piFca_create_channel)( AcPVName, 0, 0, 0,
> > &chidChannelToPV));
> >
> > //	piFca_pend_io = ( iFca_pend_io) GetProcAddress( hLibrary,
> > "_ca_pend_io@8");
> > //	if( piFca_pend_io != NULL)
> > //		lStatus = ( ( piFca_pend_io)( 10));
> >
> > //	piFca_clear_channel = ( iFca_clear_channel) GetProcAddress(
> > hLibrary, "_ca_pend_io@4");
> > //	if( piFca_clear_channel != NULL)
> > //		lStatus = ( ( piFca_clear_channel)( chidChannelToPV));
> >
> >
> > 	piFca_context_destroy = ( iFca_context_destroy) GetProcAddress(
> > hLibrary, "_ca_context_destroy@0");
> > 	if( piFca_context_destroy != NULL)
> > 		lStatus = ( ( piFca_context_destroy)());
> >
> > 	lStatus = FreeLibrary( hLibrary);
> >  	return 1;
> > }
> > =====================
> >
> >
> >
> > This is output from the program. It has
> > First-chance exception in EpicsToLabViewTest.exe (NTDLL.DLL):
> > 0xC0000005: Access Violation.
> >
> > =================
> > Loaded 'ntdll.dll', no matching symbolic information found.
> > Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic
> > information found.
> > Loaded symbols for 'C:\Epics\bin\win32-x86\ca.dll'
> > Loaded symbols for 'C:\Epics\bin\win32-x86\Com.dll'
> > Loaded 'C:\WINDOWS\system32\ws2_32.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\ws2help.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic
> information
> > found.
> > Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
> > Loaded symbols for 'C:\WINDOWS\system32\MSVCP60D.DLL'
> > Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\dnsapi.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\winrnr.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic
> > information found.
> > Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic
> > information found.
> > The thread 0xA30 has exited with code 1 (0x1).
> > First-chance exception in EpicsToLabViewTest.exe (NTDLL.DLL):
> > 0xC0000005: Access Violation.
> > The thread 0xF34 has exited with code 1 (0x1).
> > The thread 0xA0C has exited with code 1 (0x1).
> > The thread 0x930 has exited with code 1 (0x1).
> > The thread 0xFD8 has exited with code 1 (0x1).
> > The program
> > 'C:\EpicsClients\EpicsToLabViewTest\Debug\EpicsToLabViewTest.exe' has
> > exited with code 1 (0x1).
> > =================
> >
> > Couple moments.
> > 1. I use Epics 3.14.4. Visual C++ 6.0. Of course, Window XP.
> > 2. Epics dll are compiled with __stdcall. I couldn't call Epics
> function
> > until
> > 	- adding __stdcall to each "typedef int ( __stdcall *
> > iFca_context_create)( enum);"
> > 	- changing function name to name in real dll like
> > ca_context_create to _ca_context_create@4. For example,
> > 	piFca_context_create = ( iFca_context_create) GetProcAddress(
> > hLibrary, "_ca_context_create@4");
> > 	Maybe anybody know how it can be used in normal way?
> >
> > Thanks, Andrei.
#include "assert.h"

#include "windows.h"

#include "cadef.h"

typedef int ( epicsShareAPI * p_ca_context_create) 
    ( enum ca_preemptive_callback_select );

typedef void ( epicsShareAPI * p_ca_context_destroy )
    ( void );

typedef int ( epicsShareAPI * p_ca_create_channel )
(
     const char     *pChanName, 
     caCh           *pConnStateCallback, 
     void           *pUserPrivate,
     capri          priority,
     chid           *pChanID
);

typedef int ( epicsShareAPI * p_ca_clear_channel )
(
     chid
);

typedef int ( epicsShareAPI * p_ca_pend_io )
    ( ca_real timeOut );

main ()
{

    HINSTANCE hLibrary = LoadLibrary("ca.dll");
    assert ( hLibrary );
 
    p_ca_context_create pF_ca_context_create = ( p_ca_context_create ) 
        GetProcAddress( hLibrary, "_ca_context_create@4" );
    assert ( pF_ca_context_create );

    p_ca_context_destroy pF_ca_context_destroy = ( p_ca_context_destroy ) 
        GetProcAddress( hLibrary, "_ca_context_destroy@0" );
    assert ( pF_ca_context_destroy );

    p_ca_create_channel pF_ca_create_channel = ( p_ca_create_channel ) 
        GetProcAddress( hLibrary, "_ca_create_channel@20" );
    assert ( pF_ca_create_channel );

    p_ca_clear_channel pF_ca_clear_channel = ( p_ca_clear_channel ) 
        GetProcAddress( hLibrary, "_ca_clear_channel@4" );
    assert ( pF_ca_clear_channel );

    p_ca_pend_io pF_ca_pend_io = ( p_ca_pend_io ) 
        GetProcAddress( hLibrary, "_ca_pend_io@8" );
    assert ( pF_ca_pend_io );

    int status = ( *pF_ca_context_create ) 
        ( ca_disable_preemptive_callback );
    SEVCHK ( status, "context create failed" );

    chid chan;
    status = ( *pF_ca_create_channel ) 
        ( "joh:bill", 0, 0, 0, &chan );
    SEVCHK ( status, "create channel failed" );

    status = ( *pF_ca_pend_io ) ( 10.0 );
    SEVCHK ( status, "channel connect failed" );

    status = ( *pF_ca_clear_channel ) ( chan );
    SEVCHK ( status, "channel clear failed" );

    ( *pF_ca_context_destroy ) ();
}



Navigate by Date:
Prev: How to add gpib device support Iris Allard
Next: Entry 136 in Mantis Jeff Hill
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: explicit dynamic linking and ca.dll . CA bug? Liyu, Andrei
Next: Need direction in getting asyndriver build. Iris Allard
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  <20042005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·