C# 프로그래밍을 처음 사용합니다. C에서 수정 한 프로그램이 있는데, 이제 C 프로그램에서 가져온 문자열 배열을 가져와 C# 프로그램에 전달하여 해당 값을 사용하여 Oracle 데이터베이스를 쿼리 할 수 있도록해야합니다.C에서 C#으로 변환하거나 DLL을 만드시겠습니까?
이 프로그램은 컴퓨터에 연결된 모든 iButton 장치의 일련 번호를 가져 오는 데 사용됩니다. 여기
는// function prototypes
void UnLoadTMEX(void);
short LoadTMEX(void);
// globals
static FARPROC Get_Version, TMGetTypeVersion, TMEndSession;
static FARPROC TMSetup, TMNext, TMRom, ExtendedStartSession;
static FARPROC TMReadDefaultPort;
long (__fastcall *TMExtendedStartSession)(short,short,void *);
static HINSTANCE hInst;
unsigned char state_buf[5125];
//--------------------------------------------------------------------------
// Main of iSerial64
//
void main(int argc, char **argv)
{
char refresh,buf[200];
short flag,i,didsetup=0;
short ROM[9];
short PortNum,PortType;
long SHandle;
char serialtmp[2], serial[10][17];
int j = -1;
// load the TMEX driver and get pointers to functions
if (!LoadTMEX())
{
printf("ERROR, could not load IBFS64.DLL\n");
exit(0);
}
// load the TMEX driver and get pointers to functions
TMReadDefaultPort(&PortNum, &PortType);
// get the TMEX driver version
printf("Port number: %d Port type: %d\n",PortNum,PortType);
Get_Version(buf);
printf("Main Driver: %s\n",buf);
printf("TYPE%d:",PortType);
if ((short)TMGetTypeVersion(PortType,buf) < 0)
{
printf("\nNo Hardware Driver for this type found!\n");
// Unload the TMEX driver
UnLoadTMEX();
exit(0);
}
printf(" %s\n\n\n",buf);
// check the command line
if (argc > 1)
PortNum = atoi(argv[1]);
// check for valid range of PortNum
if ((PortNum < 1) || (PortNum > 15))
{
printf("ERROR, invalid port requested: %d\n",PortNum);
exit(0);
}
// loop to display the rom numbers until key hit
do
{
// get a session handle to the requested port
SHandle = TMExtendedStartSession(PortNum,PortType,NULL);
if (SHandle > 0)
{
// check to see if TMSetup has been done once
if (!didsetup)
{
flag = (short)TMSetup(SHandle);
if (flag == 1 || flag == 2)
{
printf("TMSetup complete %d\n",flag);
didsetup = 1;
}
else
{
printf("ERROR doing setup %d\n",flag);
break;
}
}
// only get the next rom after setup complete
else
{
//j was added to keep track of the serial number strings
j++;
memset(serial[j], 0, strlen(serial[j]));
flag = (short)TMNext(SHandle,(void far *)&state_buf[0]);
if (flag > 0)
{
ROM[0] = 0;
flag = (short)TMRom(SHandle, (void far *)&state_buf[0], (short far *)&ROM[0]);
for (i = 7; i >= 0; i--)
{
//This section was changed from the original
//copies raw number into string
sprintf(serialtmp, "%02X", ROM[i]);
strcat(serial[j], serialtmp);
}
printf("%s ", serial[j]);
printf("\n");
}
else
printf("end of search\n");
}
// close the opened session
TMEndSession(SHandle);
}
}
while (flag > 0);
// Unload the TMEX driver
UnLoadTMEX();
printf("iSERIAL64 end\n");
}
//--------------------------------------------------------------------------
// Load the TMEX driver and get a pointers to the functions
//
short LoadTMEX(void)
{
// attempt to get a SHandle to the TMEX driver
hInst = LoadLibrary(L"IBFS64.DLL");
// get a pointer to the function needed by loopit64
if (hInst != NULL)
{
ExtendedStartSession = GetProcAddress(hInst,"TMExtendedStartSession");
TMEndSession = GetProcAddress(hInst,"TMEndSession");
TMSetup = GetProcAddress(hInst,"TMSetup");
TMNext = GetProcAddress(hInst,"TMNext");
TMRom = GetProcAddress(hInst,"TMRom");
Get_Version = GetProcAddress(hInst,"Get_Version");
TMGetTypeVersion = GetProcAddress(hInst,"TMGetTypeVersion");
TMReadDefaultPort = GetProcAddress(hInst, "TMReadDefaultPort");
// check to make sure got ALL of the functions needed
if ((ExtendedStartSession == NULL) || (TMEndSession == NULL) ||
(TMSetup == NULL) || (TMNext == NULL) ||
(TMRom == NULL) || (Get_Version == NULL) ||
(TMGetTypeVersion == NULL) || (TMReadDefaultPort == NULL))
{
printf("ERROR, could not get a pointer to all"
" of the TMEX functions needed\n");
return 0;
}
// get a function pointer that returns a long
TMExtendedStartSession = (long (__fastcall *)(short,short,void *))ExtendedStartSession;
return 1;
}
else
return 0;
}
//--------------------------------------------------------------------------
// UnLoad the TMEX driver
//
void UnLoadTMEX(void)
{
// release the TMEX driver
FreeLibrary(hInst);
}
내가이 변환, 아니면 그냥 C DLL을 만들고 내 C# 프로그램으로 그것을 가져 오려고한다 C 코드를 무엇입니까? 제가 말씀 드렸듯이 저는 C#으로 일한 적이 없으며, 저는 인턴입니다. 사장님이 제게 C#을 배울 수 있도록이 프로젝트를 제공하고 있습니다. 어떤 도움도 크게 평가됩니다
다른 앱에서 DLL을 사용합니까? 관리 코드가 필요합니까, 아니면 관리 코드와 관리되지 않는 코드를 함께 사용할 수 있습니까? 왜 그걸 다시 쓰지 않는거야? 정말로 귀하의 질문은 무엇입니까? 당신은 그것을하는 방법을 알고 싶습니까? 아니면 당신이 그것을해야만 하는지를 알고 싶습니까? – SQLMason
음, DLL을 만들 수있을 때 변환하는 것이 합리적인지 궁금 해서요. 그러나 변환하는 것이 더 나은 학습 경험이라고 생각합니다. 이미 필요한 기능을 추가하기 위해 프로그램을 변경했습니다. – user3232337
제 질문은 어디서부터 시작해야할까요? – user3232337