Her er de funktioner som bliver includet og kaldt fra win2000 servicen. Servicen har kørt længe uden problemer, men låser hvis hun includer og bruger mit program. Kan i se om jeg skal lave noget der ikke er så smart ? Min kode følger herunder :
***************************** FUNKTION ******************************
#include "logclass.h"
#include <stdio.h>
#include <exception>
#include <typeinfo>
//#import "KOBOpenXml.dll" no_namespace
#import "msxml4.dll"
using namespace MSXML2;
#define m_printf printf
inline void EVAL_HR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
struct inputoplysninger
{
char kundenummer [11];
char brugernavn [9];
char kendeord [9];
char user_id [11];
char sprog [4];
char versionsnr [5];
char service [9];
char nummer_type [4];
char nummer [11];
char navn [36];
char adresse [36];
char post_nummer [5];
char kommunikations_type [4];
char kommunikations_nummer[71];
char personnavn [36];
char medtag_ikke_aktive [2];
char medtag_filialer [2];
char max_antal [3];
char startkey [56];
char kobnummer [11];
};
struct ratioplysninger
{
char rating_dato [11];
char rating_kode [4];
char rating_tekst [51];
char risikogruppe_kode [4];
char risikogruppe_tekst [51];
char kreditmaximum_valuta [4];
char kreditmaximum [21];
};
struct firmaopl{
char kob_nummer [11];
char cvr_nummer [11];
char jur_form_kode [4];
char status_kode [4];
char navn [71];
char adresse [36];
char post_nummer [5];
char post_distrikt [36];
char telefon_nummer [26];
char soege_hit [71];
char soege_hit_type [4];
};
struct returoplysninger
{
struct firmaopl firma[25];
struct ratioplysninger rati;
char startkey [56];
char user_id [11];
char kob_head [9];
char rec_antal [3];
char kob_mess_level [2];
char kob_mess_number [5];
char kob_mess_descri [41];
};
struct returoplysninger retopl;
struct inputoplysninger mininput;
int funk =0;
int antalvirk = 0;
CHAR *KOBres = "";
CHAR *item="";
CHAR *tagname="";
CHAR MSERVICE[250] ="";
CHAR logtxt [250] = "";
TLog *logpointer;
char* gettag(char *xmldata, char *item, char *tagname,int nr);
int findvirksomhed(void);
int logon(void);
void initarbvar(void);
void udskrivfirma(int antal);
int findvirkrati(void);
void udskrivrati(void);
void initialiser_indvar(char inbuffer[]);
void initialiser_udvar(char udbuffer[]);
void text_field(char a[], int fra, int til, char b[]);
char* strip(char tekst[]);
void strip_back(char tekst[], char nytekst[]);
void remove( int size, char input[], char output[] );
void strip_nul(char* Dst, char* Src, int srcLen);
void putnuller(char intekst[],char udtekst[],int antal);
int kald_kob(char in[], char ud[])
{
int svar=1;
int logonok = 1;
try
{
EVAL_HR(CoInitialize(NULL));
logpointer = new TLog;
strcpy(logpointer->LogfilePath,"c:\\TEMP");
strcpy(logpointer->LogfilePrefix,"\\KOBOPEN_");
strcpy(logpointer->LogfileSuffix,".LOG");
strcpy(logtxt,"");
strcat(logtxt,"*************** NYT KALD ***************");
logpointer->LogEntry(LOG_INFO,logtxt);
initialiser_indvar(in);
strcpy(logtxt,"");
strcat(logtxt,"kundenummer : ");
strcat(logtxt,mininput.kundenummer);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"brugernavn : ");
strcat(logtxt,mininput.brugernavn);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"kendeord : ");
strcat(logtxt,mininput.kendeord);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"user_id : ");
strcat(logtxt,mininput.user_id);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"sprog : ");
strcat(logtxt,mininput.sprog);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"versionsnr : ");
strcat(logtxt,mininput.versionsnr);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"service : ");
strcat(logtxt,mininput.service);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"nummer_type : ");
strcat(logtxt,mininput.nummer_type);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"nummer : ");
strcat(logtxt,mininput.nummer);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"navn : ");
strcat(logtxt,mininput.navn);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"adresse : ");
strcat(logtxt,mininput.adresse);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"kundenummer : ");
strcat(logtxt,mininput.kundenummer);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"post_nummer : ");
strcat(logtxt,mininput.post_nummer);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"kommunikations_type : ");
strcat(logtxt,mininput.kommunikations_type);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"kommunikations_nummer : ");
strcat(logtxt,mininput.kommunikations_nummer);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"personnavn : ");
strcat(logtxt,mininput.personnavn);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"medtag_ikke_aktive : ");
strcat(logtxt,mininput.medtag_ikke_aktive);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"medtag_filialer : ");
strcat(logtxt,mininput.medtag_filialer);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"max_antal : ");
strcat(logtxt,mininput.max_antal);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"startkey : ");
strcat(logtxt,mininput.startkey);
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(logtxt,"");
strcat(logtxt,"kobnummer : ");
strcat(logtxt,mininput.kobnummer);
logpointer->LogEntry(LOG_INFO,logtxt);
m_printf("\nService :%s",mininput.service);
if (strcmp(mininput.service,"FINDVIRK")==0)
funk = 0;
else
if (strcmp(mininput.service,"VIRKRATI")==0)
funk = 1;
else
funk = 3;
switch (funk)
{
case 0 :
{
initarbvar();
logonok = 1;
svar=logon();
m_printf("\nSvar fra logon : %d",svar);
if (svar==1)
{
while (logonok == 1)
{
svar=findvirksomhed();
m_printf("\nSvar fra findvirksomhed : %d",svar);
if ( (svar==0) &&
(strcmp(retopl.kob_mess_level,"1")==0) &&
(strcmp(retopl.kob_mess_number,"8100")==0) )
{
m_printf("\nVi har en logon fejl - logon udløbet");
strcpy(retopl.user_id,"");
strcpy(mininput.user_id,"");
strcpy(retopl.kob_mess_descri,"");
strcpy(retopl.kob_mess_level,"");
strcpy(retopl.kob_mess_number,"");
svar = logon();
logonok = 1;
}
else
{
logonok = 0;
}
}
}
// udskrivfirma(antalvirk);
break;
}
case 1 :
{
initarbvar();
logonok = 1;
svar=logon();
m_printf("\nSvar fra logon :%d",svar);
if (svar==1)
{
while (logonok == 1)
{
svar=findvirkrati();
m_printf("\nSvar fra virkrati : %d",svar);
if ( (svar==0) &&
(strcmp(retopl.kob_mess_level,"1")==0) &&
(strcmp(retopl.kob_mess_number,"8100")==0) )
{
m_printf("\nVi har en logon fejl - logon udløbet");
strcpy(retopl.user_id,"");
strcpy(mininput.user_id,"");
strcpy(retopl.kob_mess_descri,"");
strcpy(retopl.kob_mess_level,"");
strcpy(retopl.kob_mess_number,"");
svar = logon();
logonok = 1;
}
else
{
logonok = 0;
}
}
}
// udskrivrati();
break;
}
default : {
strcpy(retopl.kob_mess_descri,"forkert service id");
strcpy(retopl.kob_head,"FEJL");
}
}
initialiser_udvar(ud);
delete logpointer;
CoUninitialize();
return (1);
}
catch(std::exception& e)
{
strcpy(logtxt,"");
strcat(logtxt,e.what());
logpointer->LogEntry(LOG_INFO,logtxt);
strcpy(retopl.kob_mess_descri,"System fejl");
strcpy(retopl.kob_head,"FEJL");
initialiser_udvar(ud);
CoUninitialize();
delete logpointer;
return 0;
}
}
void putnuller(char intekst[], char udtekst[], int antal)
{
int i=0,x=0,y=0;
char tempchar[100]="";
strcpy(udtekst,intekst);
x=strlen(intekst);
y = antal - x;
for (i=0;i<=y-1;i++)
udtekst[i] = '0';
for (i=0; i<=x-1;i++)
{
udtekst[y+i]=intekst[i];
}
udtekst[i+y+1] = 0;
}
void strip_back(char tekst[], char nytekst[])
{
int i;
i = strlen(tekst)-1;
while ( (tekst[i] == ' ') && (tekst[i]))
{
i--;
}
if (tekst[i]!= ' ')
tekst[i+1] = 0;
nytekst = tekst;
//return(tekst);
};
char* strip(char tekst[])
{
int i = 0;
while ( (tekst[i] != ' ') && (tekst[i]))
i++;
if (tekst[i]== ' ')
tekst[i] = 0;
return(tekst);
};
void text_field(char a[], int fra, int til, char b[])
{
for (int i = fra; i <= til; i++) b[i - fra] = a[i];
b[i - fra] = '\0';
};
void initialiser_indvar(char inbuffer[])
{
text_field(inbuffer,0,9,mininput.kundenummer);
text_field(inbuffer,10,17,mininput.brugernavn);
text_field(inbuffer,18,25,mininput.kendeord);
text_field(inbuffer,26,35,mininput.user_id);
text_field(inbuffer,36,38,mininput.sprog);
text_field(inbuffer,39,42,mininput.versionsnr);
text_field(inbuffer,43,50,mininput.service);
text_field(inbuffer,51,53,mininput.nummer_type);
text_field(inbuffer,54,63,mininput.nummer);
text_field(inbuffer,64,98,mininput.navn);
text_field(inbuffer,99,133,mininput.adresse);
text_field(inbuffer,134,137,mininput.post_nummer);
text_field(inbuffer,138,140,mininput.kommunikations_type);
text_field(inbuffer,141,210,mininput.kommunikations_nummer);
text_field(inbuffer,211,245,mininput.personnavn);
text_field(inbuffer,246,246,mininput.medtag_ikke_aktive);
text_field(inbuffer,247,247,mininput.medtag_filialer);
text_field(inbuffer,248,249,mininput.max_antal);
text_field(inbuffer,250,304,mininput.startkey);
text_field(inbuffer,305,314,mininput.kobnummer);
strip_back(mininput.kundenummer,mininput.kundenummer);
strip_back(mininput.brugernavn,mininput.brugernavn);
strip_back(mininput.kendeord,mininput.kendeord);
strip_back(mininput.user_id,mininput.user_id);
strip_back(mininput.sprog,mininput.sprog);
strip_back(mininput.versionsnr,mininput.versionsnr);
strip_back(mininput.service,mininput.service);
strip_back(mininput.nummer_type,mininput.nummer_type);
strip_back(mininput.nummer,mininput.nummer);
strip_back(mininput.navn,mininput.navn);
strip_back(mininput.adresse,mininput.adresse);
strip_back(mininput.post_nummer,mininput.post_nummer);
strip_back(mininput.kommunikations_type,mininput.kommunikations_type);
strip_back(mininput.kommunikations_nummer,mininput.kommunikations_nummer);
strip_back(mininput.personnavn,mininput.personnavn);
strip_back(mininput.medtag_ikke_aktive,mininput.medtag_ikke_aktive);
strip_back(mininput.medtag_filialer,mininput.medtag_filialer);
strip_back(mininput.max_antal,mininput.max_antal);
strip_back(mininput.startkey,mininput.startkey);
strip_back(mininput.kobnummer,mininput.kobnummer);
strcpy(MSERVICE,"");
strcpy(MSERVICE ,"
http://kobopen.kob.dk/xml.asp?");
if (mininput.max_antal=="")
strcpy(mininput.max_antal,"25");
/*if (mininput.sprog !="")
{
strcat(MSERVICE,"sprog=");
strcat(MSERVICE,mininput.sprog);
}
if (mininput.versionsnr !="")
{
strcat(MSERVICE,"&versionsnr=");
strcat(MSERVICE,mininput.versionsnr);
}*/
};
void initialiser_udvar(char udbuffer[])
{
int j=0;
char tempstr[100]="";
if (strcmp(retopl.kob_head,"message") !=0)
{
for (int k=0; k<=antalvirk-1; k++)
{
strcpy(tempstr,"");
putnuller(retopl.rec_antal,tempstr,2);
strncpy(retopl.rec_antal,tempstr,2);
strcpy(tempstr,"");
putnuller(retopl.firma[k].kob_nummer,tempstr,10);
strncpy(retopl.firma[k].kob_nummer,tempstr,10);
strcpy(tempstr,"");
putnuller(retopl.firma[k].cvr_nummer,tempstr,10);
strncpy(retopl.firma[k].cvr_nummer,tempstr,10);
strcpy(tempstr,"");
putnuller(retopl.firma[k].post_nummer,tempstr,4);
strncpy(retopl.firma[k].post_nummer,tempstr,4);
}
}
else
{
strcpy(tempstr,"");
putnuller(retopl.kob_mess_level,tempstr,1);
strncpy(retopl.kob_mess_level,tempstr,1);
strcpy(tempstr,"");
putnuller(retopl.kob_mess_number,tempstr,4);
strncpy(retopl.kob_mess_number,tempstr,4);
}
strcpy(retopl.kob_head,_strupr(retopl.kob_head));
m_printf("\nHeader : %s",retopl.kob_head);
strcpy(udbuffer,"");
j+= sprintf(udbuffer + j,"%-8s",retopl.kob_head);
j+= sprintf(udbuffer + j,"%-10s",retopl.user_id);
j+= sprintf(udbuffer + j,"%2s",retopl.rec_antal);
j+= sprintf(udbuffer + j,"%-55s",retopl.startkey);
for (int i=0; i<=24; i++)
{
j+= sprintf(udbuffer + j,
"%10s%10s%-3s%-3s%-70s%-35s%4s%-35s%-25s%-70s%-3s",
retopl.firma[i].kob_nummer,
retopl.firma[i].cvr_nummer,
retopl.firma[i].jur_form_kode,
retopl.firma[i].status_kode,
retopl.firma[i].navn,
retopl.firma[i].adresse,
retopl.firma[i].post_nummer,
retopl.firma[i].post_distrikt,
retopl.firma[i].telefon_nummer,
retopl.firma[i].soege_hit,
retopl.firma[i].soege_hit_type);
};
j+= sprintf(udbuffer + j,"%-10s",retopl.rati.rating_dato);
j+= sprintf(udbuffer + j,"%-3s",retopl.rati.rating_kode);
j+= sprintf(udbuffer + j,"%-50s",retopl.rati.rating_tekst);
j+= sprintf(udbuffer + j,"%-3s",retopl.rati.risikogruppe_kode);
j+= sprintf(udbuffer + j,"%-50s",retopl.rati.risikogruppe_tekst);
j+= sprintf(udbuffer + j,"%-3s",retopl.rati.kreditmaximum_valuta);
j+= sprintf(udbuffer + j,"%-20s",retopl.rati.kreditmaximum);
j+= sprintf(udbuffer + j,"%1s",retopl.kob_mess_level);
j+= sprintf(udbuffer + j,"%4s",retopl.kob_mess_number);
j+= sprintf(udbuffer + j,"%-40s",retopl.kob_mess_descri);
};
void strip_nul(char* Dst, char* Src, int srcLen)
{
char* d;
char* s;
s = Src;
d = Dst;
for (int i=0; i<srcLen; i++)
{
if (*s != 0)
{
*d = *s;
d++;
}
s++;
}
}
void remove( int size, char input[], char output[] )
{
int j = 0;
for( int i=0; i < size; i++ )
{
if( input[i] != '\0' )
{
output[j] = input[i];
j++;
}
}
output[j] = '\0';
}
int logon(void)
{
m_printf("\nLogon kaldt med user_id :%s",mininput.user_id);
strcpy(logtxt,"");
strcat(logtxt,"Logon kaldt med user id : ");
strcat(logtxt,mininput.user_id);
logpointer->LogEntry(LOG_INFO,logtxt);
if (strcmp(mininput.user_id,"")==0)
{
IXMLDOMDocumentPtr objDOMDoc;
IXMLDOMNodeListPtr NodeList = NULL;
int len;
char message [255];
_variant_t varOut((bool)TRUE);
CHAR LOGONservice[120] ="service=logon&kundenummer=";
EVAL_HR(objDOMDoc.CreateInstance("Msxml2.DOMDocument.4.0"));
objDOMDoc->async = false;
strcpy(MSERVICE,"");
strcpy(MSERVICE ,"
http://kobopen.kob.dk/xml.asp?");
strcat(MSERVICE,LOGONservice);
strcat(MSERVICE,mininput.kundenummer);
strcat(MSERVICE,"&brugernavn=");
strcat(MSERVICE,mininput.brugernavn);
strcat(MSERVICE,"&kendeord=");
strcat(MSERVICE,mininput.kendeord);
strcat(MSERVICE,"&logon_valid=1000");
strcpy(logtxt,"");
strcat(logtxt,"Logon URL: ");
strcat(logtxt,MSERVICE);
logpointer->LogEntry(LOG_INFO,logtxt);
varOut = objDOMDoc->load(MSERVICE);
if ((bool)varOut == FALSE)
throw(0);
NodeList = objDOMDoc->childNodes;
len=NodeList->item[1]->nodeName.length();
WideCharToMultiByte(0, 0, NodeList->item[1]->nodeName, len + 1, message, len + 1, 0, 0);
strcpy(retopl.kob_head,message);
//objDOMDoc->save("c:\\xml\\logonxml.xml");
if (strcmp(message,"logon")==0)
{
item = "logon";
tagname = "user_id";
strncpy(retopl.user_id,gettag(objDOMDoc->xml,item,tagname,0),10);
objDOMDoc = NULL;
NodeList = NULL;
return(1);
}
else
{
item = "message";
tagname = "level";
strncpy(retopl.kob_mess_level,gettag(objDOMDoc->xml,item,tagname,0),1);
item = "message";
tagname = "number";
strncpy(retopl.kob_mess_number,gettag(objDOMDoc->xml,item,tagname,0),4);
item = "message";
tagname = "description";
strncpy(retopl.kob_mess_descri,gettag(objDOMDoc->xml,item,tagname,0),40);
objDOMDoc = NULL;
NodeList = NULL;
strcpy(logtxt,"");
strcat(logtxt,"Logon fejlet, fejl : Level : ");
strcat(logtxt,retopl.kob_mess_level);
strcat(logtxt," Number : ");
strcat(logtxt,retopl.kob_mess_number);
strcat(logtxt," Descript : ");
strcat(logtxt,retopl.kob_mess_descri);
logpointer->LogEntry(LOG_ERROR,logtxt);
return(0);
}
}
else
{
strcpy(retopl.user_id,mininput.user_id);
}
m_printf("\nLogon afsluttet");
logpointer->LogEntry(LOG_INFO,"Logon exit");
return(1);
};
int findvirksomhed(void)
{
m_printf("\nStar af findvirk funk");
CHAR VIRKservice [50] = "service=findvirk";
int i,x = 0;
char *datastreng = "";
int len;
char message [255];
_variant_t varOut((bool)TRUE);
IXMLDOMDocumentPtr objDOMDoc=NULL;
IXMLDOMNodeListPtr NodeList=NULL;
IXMLDOMNodePtr DOMNodePtr=NULL;
IXMLDOMElementPtr mitelPtr=NULL;
EVAL_HR(objDOMDoc.CreateInstance("Msxml2.DOMDocument.4.0"));
objDOMDoc->async = false;
strcpy(MSERVICE,"");
strcpy(MSERVICE ,"
http://kobopen.kob.dk/xml.asp?");
strcat(MSERVICE,VIRKservice);
if (strcmp(mininput.nummer_type,"")!=0)
{
strcat(MSERVICE,"&nummer_type=");
strcat(MSERVICE,mininput.nummer_type);
}
m_printf("\nnummer : %s",mininput.nummer);
if (strcmp(mininput.nummer,"0000000000")!=0)
{
strcat(MSERVICE,"&nummer=");
strcat(MSERVICE,mininput.nummer);
}
if (strcmp(mininput.navn,"")!=0)
{
strcat(MSERVICE,"&navn=");
strcat(MSERVICE,mininput.navn);
}
if (strcmp(mininput.adresse,"")!=0)
{
strcat(MSERVICE,"&adresse=");
strcat(MSERVICE,mininput.adresse);
}
if (strcmp(mininput.post_nummer,"")!=0)
{
strcat(MSERVICE,"&post_nummer=");
strcat(MSERVICE,mininput.post_nummer);
}
if (strcmp(mininput.kommunikations_type,"")!=0)
{
strcat(MSERVICE,"&kommunikations_type=");
strcat(MSERVICE,mininput.kommunikations_type);
}
if (strcmp(mininput.kommunikations_nummer,"")!=0)
{
strcat(MSERVICE,"&kommunikations_nummer=");
strcat(MSERVICE,mininput.kommunikations_nummer);
}
if (strcmp(mininput.personnavn,"")!=0)
{
strcat(MSERVICE,"&personnavn=");
strcat(MSERVICE,mininput.personnavn);
}
if (strcmp(mininput.medtag_ikke_aktive,"")!=0)
{
strcat(MSERVICE,"&medtag_ikke_aktive=");
strcat(MSERVICE,mininput.medtag_ikke_aktive);
}
if (strcmp(mininput.medtag_filialer,"")!=0)
{
strcat(MSERVICE,"&medtag_filialer=");
strcat(MSERVICE,mininput.medtag_filialer);
}
if (strcmp(mininput.max_antal,"")!=0)
{
strcat(MSERVICE,"&max_antal=");
strcat(MSERVICE,mininput.max_antal);
}
if (strcmp(mininput.startkey,"")!=0)
{
strcat(MSERVICE, "&start_key=" );
strcat(MSERVICE, mininput.startkey);
}
strcat(MSERVICE, "&user_id=");
strcat(MSERVICE, retopl.user_id);
strcpy(logtxt,"");
strcat(logtxt,"FINDVIRK URL: ");
strcat(logtxt,MSERVICE);
logpointer->LogEntry(LOG_INFO,logtxt);
varOut = objDOMDoc->load(MSERVICE);
if ((bool)varOut == FALSE)
throw(0);
//objDOMDoc->save("c:\\xml\\servicexml.xml");
m_printf("\nSerive : %s",MSERVICE);
NodeList = objDOMDoc->childNodes;
len=NodeList->item[1]->nodeName.length();
WideCharToMultiByte(0, 0, NodeList->item[1]->nodeName, len + 1, message, len + 1, 0, 0);
strcpy(retopl.kob_head,message);
if (strcmp(retopl.kob_head,"findvirk")==0)
{
NodeList = objDOMDoc->getElementsByTagName("virksomhed");
antalvirk = NodeList->length;
i = antalvirk-1;
for (x=0; x<=i; x++)
{
item = "virksomhed";
tagname = "kob_nummer";
strncpy(retopl.firma[x].kob_nummer,gettag(objDOMDoc->xml,item,tagname,x),10);
item = "virksomhed";
tagname = "cvr_nummer";
strncpy(retopl.firma[x].cvr_nummer,gettag(objDOMDoc->xml,item,tagname,x),10);
item = "virksomhed";
tagname = "jur_form_kode";
strncpy(retopl.firma[x].jur_form_kode,gettag(objDOMDoc->xml,item,tagname,x),3);
item = "virksomhed";
tagname = "status_kode";
strncpy(retopl.firma[x].status_kode,gettag(objDOMDoc->xml,item,tagname,x),3);
item = "virksomhed";
tagname = "navn";
strncpy(retopl.firma[x].navn,gettag(objDOMDoc->xml,item,tagname,x),70);
item = "virksomhed";
tagname = "adresse";
strncpy(retopl.firma[x].adresse,gettag(objDOMDoc->xml,item,tagname,x),35);
item = "virksomhed";
tagname = "post_nummer";
strncpy(retopl.firma[x].post_nummer,gettag(objDOMDoc->xml,item,tagname,x),4);
item = "virksomhed";
tagname = "post_distrikt";
strncpy(retopl.firma[x].post_distrikt,gettag(objDOMDoc->xml,item,tagname,x),35);
item = "virksomhed";
tagname = "telefon_nummer";
strncpy(retopl.firma[x].telefon_nummer,gettag(objDOMDoc->xml,item,tagname,x),25);
item = "virksomhed";
tagname = "soege_hit";
strncpy(retopl.firma[x].soege_hit,gettag(objDOMDoc->xml,item,tagname,x),75);
item = "virksomhed";
tagname = "soege_hit_type";
strncpy(retopl.firma[x].soege_hit_type,gettag(objDOMDoc->xml,item,tagname,x),3);
};
logpointer->LogEntry(LOG_INFO,"Virksomhed fundet");
//objDOMDoc->save("c:\\mfa\\next.xml");
m_printf("\nAntal virksomhedder : %d",antalvirk);
if ( (antalvirk==atoi(mininput.max_antal)) ||
(antalvirk==25) )
{
item = "findvirk";
tagname = "next_key";
strncpy(retopl.startkey,gettag(objDOMDoc->xml,item,tagname,0),10);
}
else
strncpy(retopl.startkey,"",1);
m_printf("\nStartkey :%s",retopl.startkey);
NodeList = objDOMDoc->getElementsByTagName("virksomhed");
antalvirk = NodeList->length;
_itoa(antalvirk,retopl.rec_antal,10);
objDOMDoc = NULL;
NodeList = NULL;
mitelPtr = NULL;
DOMNodePtr= NULL;
}
else
{
m_printf("\nDer er en message i findvirk");
item = "message";
tagname = "level";
strncpy(retopl.kob_mess_level,gettag(objDOMDoc->xml,item,tagname,0),1);
item = "message";
tagname = "number";
strncpy(retopl.kob_mess_number,gettag(objDOMDoc->xml,item,tagname,0),4);
item = "message";
tagname = "description";
strncpy(retopl.kob_mess_descri,gettag(objDOMDoc->xml,item,tagname,0),40);
strcpy(logtxt,"");
strcat(logtxt,"Virksomhed fejlet, fejl : Level : ");
strcat(logtxt,retopl.kob_mess_level);
strcat(logtxt," Number : ");
strcat(logtxt,retopl.kob_mess_number);
strcat(logtxt," Descript : ");
strcat(logtxt,retopl.kob_mess_descri);
logpointer->LogEntry(LOG_ERROR,logtxt);
objDOMDoc = NULL;
NodeList = NULL;
mitelPtr = NULL;
DOMNodePtr= NULL;
return(0);
};
logpointer->LogEntry(LOG_INFO,"Virksomhed kaldt ok");
return(1);
};
char* gettag(char *xmldata, char *item, char *tagname, int nr)
{
//printf("\nStart GETTAG");
try {
int len;
//char * message = new char [255];
char nybesked[255];
char *tekst;
IXMLDOMDocumentPtr docPtr =NULL;
IXMLDOMNodeListPtr NodeListPtr=NULL;
IXMLDOMNodePtr DOMNodePtr=NULL;
//init
EVAL_HR(docPtr.CreateInstance("Msxml2.DOMDocument.4.0"));
_variant_t varOut((bool)TRUE);
docPtr->async = false;
docPtr->loadXML(xmldata);
NodeListPtr = docPtr->getElementsByTagName(item);
DOMNodePtr = NodeListPtr->item[nr]->selectSingleNode(tagname);
if (DOMNodePtr != NULL)
{
len=DOMNodePtr->text.length();
//WideCharToMultiByte(0, 0, DOMNodePtr->text, len + 1, message, len + 1, 0, 0);
WideCharToMultiByte(0, 0, DOMNodePtr->text, len + 1, nybesked, len + 1, 0, 0);
}
else
{
strcpy(nybesked,"");
}
tekst = nybesked;
docPtr = NULL;
NodeListPtr = NULL;
DOMNodePtr = NULL;
return(tekst);
}
catch(...)
{
logpointer->LogEntry(LOG_ERROR,"Fejl i gettag funktion");
m_printf("\nfejl i gettag funktion");
strcpy(retopl.kob_mess_descri,"System fejl i - gettag");
strcpy(retopl.kob_head,"FEJL");
return(0);
}
}
int findvirkrati(void)
{
m_printf("\nStart på virkrati funktion");
CHAR MSERVICE[250] ="";
CHAR RATIservice [50] = "service=virkrati&KOB_nummer=";
CHAR MURL[35] ="
http://kobopen.kob.dk/xml.asp?"; int x = 0;
char *datastreng = "";
int len;
char message [255];
_variant_t varOut((bool)TRUE);
IXMLDOMDocumentPtr objDOMDoc=NULL;
IXMLDOMNodeListPtr NodeList=NULL;
EVAL_HR(objDOMDoc.CreateInstance("Msxml2.DOMDocument.4.0"));
objDOMDoc->async = false;
strcpy(MSERVICE,"");
strcat(MSERVICE,MURL);
strcat(MSERVICE,RATIservice);
strcat(MSERVICE, mininput.kobnummer);
strcat(MSERVICE, "&user_id=");
strcat(MSERVICE, retopl.user_id);
m_printf("\nService : %s",MSERVICE);
logpointer->LogEntry(LOG_INFO,"kalder virkrati");
strcpy(logtxt,"");
strcat(logtxt,"VIRKRATI URL: ");
strcat(logtxt,MSERVICE);
logpointer->LogEntry(LOG_INFO,logtxt);
varOut = objDOMDoc->load(MSERVICE);
if ((bool)varOut == FALSE)
throw(0);
//objDOMDoc->save("c:\\xml\\findratixml.xml");
NodeList = objDOMDoc->childNodes;
len=NodeList->item[1]->nodeName.length();
WideCharToMultiByte(0, 0, NodeList->item[1]->nodeName, len + 1, message, len + 1, 0, 0);
strcpy(retopl.kob_head,message);
if (strcmp(retopl.kob_head,"virkrati")==0)
{
NodeList = objDOMDoc->childNodes;
len=NodeList->item[1]->nodeName.length();
WideCharToMultiByte(0, 0, NodeList->item[1]->nodeName, len + 1, message, len + 1, 0, 0);
strcpy(retopl.kob_head,message);
item = "rating_data";
tagname = "rating_dato";
strncpy(retopl.rati.rating_dato,gettag(objDOMDoc->xml,item,tagname,x),10);
item = "rating_data";
tagname = "rating_kode";
strncpy(retopl.rati.rating_kode,gettag(objDOMDoc->xml,item,tagname,x),3);
item = "rating_data";
tagname = "rating_tekst";
strncpy(retopl.rati.rating_tekst,gettag(objDOMDoc->xml,item,tagname,x),50);
item = "rating_data";
tagname = "risikogruppe_kode";
strncpy(retopl.rati.risikogruppe_kode,gettag(objDOMDoc->xml,item,tagname,x),3);
item = "rating_data";
tagname = "risikogruppe_tekst";
strncpy(retopl.rati.risikogruppe_tekst,gettag(objDOMDoc->xml,item,tagname,x),50);
item = "rating_data";
tagname = "kreditmaximum_valuta";
strncpy(retopl.rati.kreditmaximum_valuta,gettag(objDOMDoc->xml,item,tagname,x),3);
item = "rating_data";
tagname = "kreditmaximum";
strncpy(retopl.rati.kreditmaximum,gettag(objDOMDoc->xml,item,tagname,x),20);
objDOMDoc = NULL;
NodeList = NULL;
}
else
{
item = "message";
tagname = "level";
strncpy(retopl.kob_mess_level,gettag(objDOMDoc->xml,item,tagname,0),1);
item = "message";
tagname = "number";
strncpy(retopl.kob_mess_number,gettag(objDOMDoc->xml,item,tagname,0),4);
item = "message";
tagname = "description";
strncpy(retopl.kob_mess_descri,gettag(objDOMDoc->xml,item,tagname,0),40);
strcpy(logtxt,"");
strcat(logtxt,"Virkrati fejlet, fejl : Level : ");
strcat(logtxt,retopl.kob_mess_level);
strcat(logtxt," Number : ");
strcat(logtxt,retopl.kob_mess_number);
strcat(logtxt," Descript : ");
strcat(logtxt,retopl.kob_mess_descri);
logpointer->LogEntry(LOG_ERROR,logtxt);
objDOMDoc = NULL;
NodeList = NULL;
return(0);
}
logpointer->LogEntry(LOG_INFO,"Virkrati kaldt ok");
return(1);
};
void initarbvar(void)
{
int i;
for (i=0;i<=24;i++)
{
strcpy(retopl.firma[i].kob_nummer , "");
strcpy(retopl.firma[i].cvr_nummer , "");
strcpy(retopl.firma[i].jur_form_kode , "");
strcpy(retopl.firma[i].status_kode , "");
strcpy(retopl.firma[i].navn , "");
strcpy(retopl.firma[i].adresse , "");
strcpy(retopl.firma[i].post_nummer , "");
strcpy(retopl.firma[i].post_distrikt , "");
strcpy(retopl.firma[i].telefon_nummer , "");
strcpy(retopl.firma[i].soege_hit , "");
strcpy(retopl.firma[i].soege_hit_type, "");
}
strcpy(retopl.rati.kreditmaximum,"");
strcpy(retopl.rati.kreditmaximum_valuta,"");
strcpy(retopl.rati.rating_dato,"");
strcpy(retopl.rati.rating_kode,"");
strcpy(retopl.rati.rating_tekst,"");
strcpy(retopl.rati.risikogruppe_kode,"");
strcpy(retopl.rati.risikogruppe_tekst,"");
strcpy(retopl.kob_head,"");
strcpy(retopl.kob_mess_descri,"");
strcpy(retopl.kob_mess_level,"");
strcpy(retopl.kob_mess_number,"");
strcpy(retopl.rec_antal,"");
strcpy(retopl.startkey,"");
strcpy(retopl.user_id,"");
}
void udskrivrati(void)
{
m_printf("\nUdskriv : %s",retopl.rati.rating_dato);
m_printf("\nUdskriv : %s",retopl.rati.rating_kode);
m_printf("\nUdskriv : %s",retopl.rati.rating_tekst);
m_printf("\nUdskriv : %s",retopl.rati.risikogruppe_kode);
m_printf("\nUdskriv : %s",retopl.rati.risikogruppe_tekst);
m_printf("\nUdskriv : %s",retopl.rati.kreditmaximum_valuta);
m_printf("\nUdskriv : %s",retopl.rati.kreditmaximum);
};
void udskrivfirma(int antal)
{
int i;
for (i=0;i<=antal-1;i++)
{
m_printf("\n*******************************************************");
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].kob_nummer);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].cvr_nummer);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].jur_form_kode);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].status_kode);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].navn);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].adresse);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].post_nummer);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].post_distrikt);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].telefon_nummer);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].soege_hit);
m_printf("\n");
m_printf("Udskriv : %s",retopl.firma[i].soege_hit_type);
}
}