C Interface Help

C Interface Help

I continue to have problems with interfaces to C programs - I guess I just don't quite get it. I had one of our C programmers write a function to return the NIC physical address and am trying to interface with this function from my CVF code. The C header file for the function is shown below.

-----------------------------

#ifndef _GETMACNETBIOS_H
#define _GETMACNETBIOS_H
/**
* Queries the netbios for the machine Id
*
* ARGUEMENTS: An address pointer which will contain the mac id string (6bytes)
*
* RETURNS 1 if call was successful. 0 if not successful.
*/
int returnMACAddress(char *addrPtr);
#endif

---------------------------------

The following C code works fine:

---------------------------------
#include
#include "GetMACNETBIOS.h"
int main(int argc, char *argv[])
{
unsigned char macid[8];

if (returnMACAddress(macid))
printf("mac id is %02X-%02X-%02X-%02X-%02X-%02X
",macid[0],macid[1],macid[2],macid[3],macid[4],macid[5]);
else
printf("couldn't find the macid
");
}
----------------------------

But the following CVF code gives me an unresolved external:

----------------------------
program getmactest

character*6 MACAddress
integer ireturn
integer lpMACAddress

interface
integer function returnMACAddress(lpMACAddress)
integer lpMACAddress
end function
end interface

lpMACAddress = loc(MACAddress)

ireturn = returnMacAddress(lpMACAddress)

write(*,'(a6)') MACAddress
pause
end

------------------------------

The specific linker error is:

------------------------------

getmactest.obj : error LNK2001: unresolved external symbol _RETURNMACADDRESS@4
Debug/getmac.exe : fatal error LNK1120: 1 unresolved externals

------------------------------
Any suggestions would be appreciated

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

My additions are bold.
-----------------------------

#ifndef _GETMACNETBIOS_H
#define _GETMACNETBIOS_H
#ifdef __cplusplus
extern "C" {
#endif

/**
* Queries the netbios for the machine Id
*
* ARGUEMENTS: An address pointer which will contain the mac id string (6bytes)
*
* RETURNS 1 if call was successful. 0 if not successful.
*/
int returnMACAddress(char *addrPtr);
#ifdef __cplusplus
} //extern "C"
#endif

#endif //_GETMACNETBIOS_H
----------------------------
#include
#include "GetMACNETBIOS.h"
int main(int argc, char *argv[])
{
unsigned char macid[8];

if (returnMACAddress(macid))
printf("mac id is %02X-%02X-%02X-%02X-%02X-%02X
",macid[0],macid[1],macid[2],macid[3],macid[4],macid[5]);
else
printf("couldn't find the macid
");
}
----------------------------
program getmactest

character*6 MACAddress
integer ireturn
integer lpMACAddress

interface
integer function returnMACAddress(lpMACAddress)
!DEC$ATTRIBUTES C, DECORATE, ALIAS: "returnMACAddress":: returnMACAddress
integer lpMACAddress
end function
end interface

lpMACAddress = loc(MACAddress)

ireturn = returnMacAddress(lpMACAddress)

write(*,'(a6)') MACAddress
pause
end

HTH
Jugoslav

Jugoslav www.xeffort.com

Thanks jugoslavdujic. As I said, I haven't got the details down precisely on C++ interfaces. I don't know enough about C++ and our C++ programmer doesn't know enough about Visual Fortran to do either of us any good. Anyway, it works fine...Thanks again.

Login to leave a comment.