|
Thanks for the reply.
DavidCrow wrote:
No, new and realloc() are not compatible.
What would you advise me to do then? Should I just new a new portion of memory, memcpy the contents and then delete the old one?
What would you say?
dNimrod#X
________________________
|
|
|
|
|
new is an operator, while realloc() and memcpy() are functions. If you want to be able to use realloc() , use malloc() instead of the new operator. Memory allocated by malloc() should be freed by calling free() .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
dNimrod#X wrote:
Should I just new a new portion of memory, memcpy the contents and then delete the old one?
You can but new is best used for allocating fixed-size memory blocks and objects.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
You can but new is best used for allocating fixed-size memory blocks and objects.
Ha, I see... so I'm better off using malloc from the start.
Thanks a lot for the valuable feedback.
dNimrod#X
________________________
|
|
|
|
|
What are you trying to do.
Is the memory for an object with a constructor/destructor ?
...cmk
Save the whales - collect the whole set
|
|
|
|
|
cmk wrote:
Is the memory for an object with a constructor/destructor ?
No it's for a variable-sized custom control own content buffer -- it may need a larger/lesser quantity of memory at a given time. I therefore need to expand/shrink the buffer according to the needs at that exact time.
dNimrod#X
________________________
|
|
|
|
|
forget aout reallocating memory, for most.
a) new/delete call Ctor and DTor of the element(s), which alloc does not
b) realloc isn't as useful or performant as one would wish, unless you have a single-threaded application and all the reallocations happen in one "block" (in which case it's typically possible, if painful, to calcuilate the total length first and allocate once).
The worst performance hit is not overallocation, but fragmentation, and typical "container" or "string builder" classes are designed to minimize that. The overhead of allocating a larger buffer and copying data is often negligible.
I would recommend using a container with contiguous memory (such as std::vector<byte> for this.
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
If the memory is just for 'blob' data (ie no constructors/destructors need to be called) then just use ?alloc/realloc/free.
The only real reason to use new/delete is to have the constructors/destructors called automatically.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Does anybody know how to change file associations from within M$ VC++ 6.
-Thanks
Mark
As you journey through life take a minute every now and then to give a thought for the other fellow.
He could be plotting something.
-Hagar the Horrible
|
|
|
|
|
A guess would be Shell API's and/or Registry entries.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
http://www.jrsoftware.org/isfaq.php#assoc[^] lists the registry entries needed to set up file associations.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi there, before you get ready to have a go at me... I do know very well how to declare variables. What I'd like to know if there is a number limit to the total amount of declarations that can be declared. You see, I'm creating a Win32Console app; the app will have a nice little number-accessed menu system - and the menus will have sub-menus. As you can gather, a lot of variables will be needed for the amount of choices that will be asked!
Can I organise my declarations on a separate file and link it to my main .cpp file? If so... could someone tell me please! Thanks for your help.
I'm using Microsoft Visual C++ 6.0 Standard Edition
drjake
|
|
|
|
|
drjake wrote:
if there is a number limit to the total amount of declarations that can be declared
Don't worry about that, just declare all the variables you need.
If you exceed the limit, whatever that is, post the information here so we will know... then shoot yourself for writing a pile of junk application that exceeded the limit of allowable variables.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
lol... I know console mode is very limited and by the looks of it, has pushed me to the limit to creating many variables!
MFC would do away with creating so many variables to construct a menu system - but I want to complete my project in console mode as a challenge and because I want to know C++ coding real good! If I exceed the limit (which I doubt!) I'd be happy to inform others
As for the other question about locating the variables on another file... anyone know if it is possible? I wouldn't mind cleaning up my .cpp file with data I would rarely need to look at.
Thanks for replying palbano!
drjake
|
|
|
|
|
drjake wrote:
by the looks of it, has pushed me to the limit
Are you getting compile errors? If so post them.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Oh, no, I'm not getting any compiler errors... all is working surprisingly well with my program. Although, due to me using switch case statements I've had to modify my coding so that sub-menus worked. After the program works out a question asked, it returns to main(). The main menu has 7 choices:
1. Areas
2. Volumes
3. Conversions
4. Percentages
5. Geometry (Angles)
6. Density and Speed
7. Basic maths
Each choice has a sub-menu allowing more options to the user:
Areas
--Rectangles
--Triangles
--Parallelograms
--Trapeziums
--Circles
Volumes
--Cuboids
--Prisms
Conversions
--Hours to minutes
--Pounds to Dollars
Percentages
--Type 1 (These are identified by the \"%\" symbol in the question)
--Type 2 (These are identified by the word \"percentage\" in the question)
--Type 3 (These are identified by them NOT giving you the \"original value\")
Geometry (Angles)
--Triangles
--Straight lines
--4-sided shapes
--Round points
--Exterior angles of triangles
--Isosceles triangles
--Parallel lines
Density and Speed
--Density = Mass / Volume
--Speed = Distance / Time
As you can see, quite a menu that is! lol I'd like to prove that someone with just over 1 weeks experience can do a useful C++ created tool! I've quickly learned that switch case within switch case... and so on, can be quite confusing! lol
drjake
|
|
|
|
|
I suggest you take a step back and re-think your design, now that you have some expirence. I suspect from your description that you have made some mistakes in design.
In programing we often say plan to throw one away, and you have just hit one good reason: until you have something close to working you really don't know what pitfalls you need to design around. Expirence will help, but the only way to get it is to do it wrong.
Without seeing your code I cannot say where (or even if!) you went wrong. However I can tell you that menu driven apps normally do not have excessive variables in one method.
Remember, GUI/MFC apps do not do anything that you cannot do with a command line menu. While you don't want all the complexity those systems provide, learning a little about how they solve your problem can help you figure out how to solve it.
As for your switch in a switch: generally that is a good place for a function call, if you haven't done that already.
|
|
|
|
|
There are limits to the number of symbols (variables, types, and function names) you can declare, but I doubt very much that you'll encounter it.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hello ,
We are trying to access some functions written in our
"SAP R-3 system" using a remote function call. SAP R-3 also generates C Code which we can use to compile interfaces that can test these functions. The text file that comes as a help file when we generate code says that it is meant for generating executable. It however mentions nothing about the code being generated not being fit for using as a dll.
I generated C Code for one such function and then made an .exe project using Visual C++ and tested it and it seems to work fine just as the documentation claims.
However when I use the same code to create a Visual C++ dll projet everything works and I get to the point of making the dll. But when I register the .dll file using REGSVR32 I get an error that reads
"the dll was loaded but the DLL Server Register Entry point was not found."
I do not know, what is it that I am doing wrong here.
Or rather my question would be
1). What special things need to be added or removed or taken care of in my C Code when I am trying to compile it into a DLL
2). I am attaching the code below, that I am using to compile into a DLL. Please feel free to have a look and tell me if there is something you feel that's causing the
trouble.
Any help with this is deeply appreciated.
Regards ,
Pradhip.S
-----------------------------------------------------------
// Code generated by SAP and Visual C++ together.
// SAPCConnect.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "saprfccl.h"
#if !defined(SAPonWINDOWS) && !defined(SAPonNT)
#define __min(a,b) (((a)<(b))?(a):(b))
#define OUT(text,pos) printf("%*.0s",pos,text); printf("%s\n",text); if (outfile!=NULL) fprintf(outfile,"=%s\n",text)
#endif
#define NL printf("\n")
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
/*
------------------------------------------------------------------------
SAP AG - R/3 Remote Function Call Interface Generation
RFC_ANSIC_CL_EXP EN 46C
07/19/2004 20:49
Complete ANSI C client example
saprfccl.c
------------------------------------------------------------------------
*/
static FILE *infile,*outfile,*logfile;
void LOG(const RFC_HANDLE hRfc, const char *text,const char *str)
{ if (logfile!=NULL) { fprintf(logfile,"%d %s %s\n",hRfc,text,str); fflush(logfile); } }
typedef void (WIN_DLL_EXPORT_FLAGS * RFC_HELP)(const char *topic, const char *subtopic, const char *text);
static RFC_HELP rfc_help;
void WIN_DLL_EXPORT_FLAGS hlp_y_sd_coa_shipinfo_down(const char *topic, const char *subtopic, const char *text);
void help(const char *topic, const char *subtopic, const char *text)
{
/* general help */
if (strcmp(topic,"h")==0) {
OUT("This is a client example programm for SAP Remote Function Call.",6);
OUT("The program was generated by the R/3 RFC Interface Generator.",6);
OUT("For further information about the example see saprfc cl.txt.",6);
OUT("To get help using the example, answer '?' on any item.",6);
OUT("The example has been generated for function module:",6); NL;
OUT("- Y_SD_COA_SHIPINFO_DOWN",8);
OUT(" Lieferinfo an Versandsubsystem.",8); NL; }
/* program arguments help */
if (strcmp(topic,"l")==0) {
OUT("To logon answer 'y' and type in destination, client, user etc.",6);
OUT("Otherwise perform logon using following program arguments:",6); NL;
OUT("-d <destination>",8);
OUT("-c <client>",8);
OUT("-u <user>",8);
OUT("-p <password>",8);
OUT("-l <language>",8);
OUT("-2 R/2 connection",8);
OUT("-3 R/3 connection",8);
OUT("-h <hostname>",8);
OUT("-s <system number="">",8);
OUT("-g <gateway host="">",8);
OUT("-x <gateway service="">",8);
OUT("-t trace",8);
OUT("-i <filename> input from file",8);
OUT("-o <filename> output to file",8);
OUT("-log <filename> log events file",8);
OUT("-? this text",8); NL; }
/* logon help */
if (strcmp(topic,"li")==0) {
if (strcmp(subtopic,"destination")==0) {
OUT("name of the R/3 or R/2 system, e.g 'C11'.",8); NL; }
if (strcmp(subtopic,"client")==0) {
OUT("R/3 or R/2 client number, e.g. '000'.",8); NL; }
if (strcmp(subtopic,"user")==0) {
OUT("R/3 user or R/2 CPI-C user.",8); NL; }
if (strcmp(subtopic,"password")==0) {
OUT("R/3 password or R/2 CPI-C password.",8); NL; }
if (strcmp(subtopic,"language")==0) {
OUT("system language of the R/3 or R/2 system, e.g. 'E'.",8); NL; }
if (strcmp(subtopic,"mode")==0) {
OUT("determines R/3 or R/2 connection.",8); NL; }
if (strcmp(subtopic,"hostname")==0) {
OUT("hostname of the R/3 application server, e.g. 'hs0000'.",8); NL; }
if (strcmp(subtopic,"system number")==0) {
OUT("system number of the R/3 System, e.g. '00'.",8); NL; }
if (strcmp(subtopic,"gateway host")==0) {
OUT("hostname of the R/3 or R/2 gateway, e.g. 'is0000'.",8); NL; }
if (strcmp(subtopic,"gateway service")==0) {
OUT("name of the R/3 or R/2 gateway service, e.g. 'sapgw00'",8); NL; }
if (strcmp(subtopic,"trace")==0) {
OUT("trace written to 'dev_rfc'.",8); NL; } }
/* input help */
if (strcmp(topic,"i")==0) {
OUT("To input function module parameters, answer 'y' and type in",6);
OUT("parameter values and append table rows if necessary.",6); NL; }
if ((strcmp(topic,"isi")==0)||(strcmp(topic,"esi")==0)) {
OUT("To fill in the structure, answer 'y' and type in structure fields.",10); NL; }
if ((strcmp(topic,"iso")==0)||(strcmp(topic,"eso")==0)) {
OUT("To display the structure fields, answer 'y'.",10); NL; }
if (strcmp(topic,"ti")==0) {
OUT("To append a table row, answer 'y' and type in table row fields.",10); NL; }
if (strcmp(topic,"to")==0) {
OUT("To get the table row and display the row fields, answer 'y' or '*' for all rows.",10); NL; }
if (strcmp(topic,"xi")==0) {
OUT("Terminates the function. To raise the exception, answer 'y'.",10); NL; }
if (strcmp(topic,"xo")==0) {
OUT("Terminated the called function.",10); NL; }
if (strcmp(topic,"c")==0) {
OUT("To call the function module, answer 'y'.",6); NL; }
if (strcmp(topic,"a")==0) {
OUT("To call the function module again, answer 'y'.",6); NL; }
/* end info */
if (strcmp(topic,"end")==0) {
OUT("Thank you for using the SAP Business Application Programming Interface",2);
OUT("and SAP Remote Function Call.",2); NL; }
if (rfc_help!=NULL) rfc_help(topic, subtopic, text);
}
void INS(const char *topic,const char *subtopic,const char *text,const unsigned pos,const unsigned len,char *str)
{
int c=0;
do { printf("%*.0s",pos,text); printf("%-*s : ",len,text);
if (infile!=NULL) { /* read from input file comparing input event (text) */
do { c=getc(infile); if (c==EOF) { OUT("error reading input file",0); exit(1); }
fgets(str,1024,infile); *(str+strlen(str)-1) = '\0'; } while ((c!='=')||(strcmp(text,str)!=0));
c=getc(infile); if (c==EOF) { OUT("error reading input file",0); exit(1); }
fgets(str,1024,infile); *(str+strlen(str)-1) = '\0'; printf("%s\n",str); } /* cut CR/LF and stdout */
else
gets(str); /* read from stdin */
if (outfile!=NULL) fprintf(outfile,"=%s\n<%s\n",text,str); /* write output file */
if (str[0]=='?') help(topic,subtopic,text); } while (str[0]=='?');
return;
}
void OUTS(const char *text,const unsigned pos,const unsigned len,char *str)
{
printf("%*.0s",pos,text); printf("%-*s : %s\n",len,text,str);
if (outfile!=NULL) fprintf(outfile,"=%s\n>%s\n",text,str);
return;
}
#define SETCHAR(var,str) memcpy(var,str,__min(strlen(str),sizeof(var))); \
if (sizeof(var)>strlen(str)) memset(var+strlen(str),' ',sizeof(var)-strlen(str))
#define GETCHAR(var,str) sprintf(str,"%.*s",sizeof(var),var)
#define SETDATE(var,str) memcpy(var,str,__min(strlen(str),sizeof(var))); \
if (sizeof(var)>strlen(str)) memset(var+strlen(str),'0',sizeof(var)-strlen(str))
#define GETDATE(var,str) sprintf(str,"%.*s",sizeof(var),var)
#define SETFLOAT(var,str) *var=atof(str);
#define GETFLOAT(var,str) sprintf(str,"%f",var);
#define SETINT(var,str) *var=atol(str);
#define GETINT(var,str) sprintf(str,"%ld",var);
#define SETNUM(var,str) memcpy(var+(sizeof(var)-__min(strlen(str),sizeof (var))),str,__min(strlen(str),sizeof(var))); \
if (sizeof(var)>strlen(str)) memset(var,'0',sizeof(var)-strlen(str))
#define GETNUM(var,str) sprintf(str,"%.*s",sizeof(var),var)
#define SETTIME(var,str) memcpy(var,str,__min(strlen(str),sizeof(var))); \
if (sizeof(var)>strlen(str)) memset(var+strlen(str),'0',sizeof(var)-strlen(str))
#define GETTIME(var,str) sprintf(str,"%.*s",sizeof(var),var)
#define SETINT1(var,str) *var=atoi(str);
#define GETINT1(var,str) sprintf(str,"%hu",var);
#define SETINT2(var,str) *var=atoi(str);
#define GETINT2(var,str) sprintf(str,"%d",var);
#define SETBYTE(var,str) str2nbyte(str,var,sizeof(var))
#define GETBYTE(var,str) nbyte2str(str,var,sizeof(var))
void str2nbyte(char *str,unsigned char *byte,size_t size)
{
/* convert string to byte, e.g. str "818283" to byte 'abc' */
size_t c; char tmp[1024]; int i;
strcpy(tmp,str); for (c=0;c<strlen(tmp);++c) tmp[c]="toupper(tmp[c]);
" for="" (c="strlen(tmp);c<(size<<1);c++)" ;
="" {="" sscanf(&="" tmp[c<<1],"%2x",&="" i);="" byte[c]="i;" }
}
void="" nbyte2str(char="" *str,unsigned="" char="" *byte,size_t="" size)
{
="" *="" convert="" byte="" to="" string,="" e.g.="" 'abc'="" str="" "818283"=""
="" size_t="" c;
="" (="" c="0;" c<size;="" c++="" )="" sprintf(="" &str[c<<1],="" "%02x",="" );
="" str[size<<1]="0;
}
#define" setbcd(var,str,dec)="" str2nbcd(str,var,sizeof(var),dec)
#define="" getbcd(var,str,dec)="" nbcd2str(str,var,sizeof(var),dec)
void="" str2nbcd(char="" *bcd,size_t="" size,="" int="" decimals)
{
="" string="" bcd,="" "+012.3"="" bcd="" '01230c'="" length="" 3="" decimals="" 2="" s[1024],*p;="" c,="" strs="size<<1;
" if="" (str[0]="='-')" {s[strs-1]="D" ;="" str++;}
="" else="" (p="strchr(str,'.'))" *(p++)="0;" p="str+strlen(str);
" (strlen(str)="">c) memcpy(s,str+strlen(str)-c,c);
else {memset(s,'0',c-strlen(str)); memcpy(s+c-strlen(str),str,strlen(str));}
while((*p) && (c < strs-1)) s[c++]=*(p++);
while(c < strs-1) s[c++]='0';
str2nbyte(s,bcd,size);
}
void nbcd2str(char *str,unsigned char *bcd,size_t size,int decimals)
{
/* convert bcd to string, e.g. bcd '01230C' length 3 decimals 2 to str "+012.30" */
char s[1024]; size_t c, strs=size<<1;
nbyte2str(s,bcd,size);
if (s[strs-1]=='D') *(str++)='-'; else *(str++)='+';
for(c=0;c<strs-decimals-1;c++) *(str++)="s[c];
" if="" (decimals="">0) { *(str++)='.'; while (c<strs-1) *(str++)="s[c++];}
" *str="0;
}
static" char*="" str2upper(char="" *str)
{
="" unsigned="" i;
="" for="" (i="0;i<strlen(str);++i)" str[i]="toupper(str[i]);
" return="" str;
}
#ifdef="" saponwindows
#include="" <graph.h="">
static void getpassword(char *password,int length)
{
short activeChild;
int i = 0 ;
if (infile!=NULL) { INS("li","password","password",6,35,password); return; }
printf("%6.0s",""); printf("%-35s : ","password"); activeChild = _wggetactive();
if (activeChild != -1) _wgclose(activeChild);
activeChild = _wgopen("Logon"); _wgsetactive(activeChild); _outtext("password : ");
while ((*password++ = (char) _inchar()) != '\r') { if (i++ >= length - 1) break; }
*(--password) = 0; _wgclose (activeChild);
if (password[-i]=='?') printf("?\n"); else if (password[-i]==0) printf("\n"); else printf("*\n");
if (outfile!=NULL) { fprintf(outfile,"=%s\n","password"); if (password[-i]=='?') fprintf(outfile," 0) strncpy(lDestination,str2upper(s),3);
INS("li","client","client [101]",6,35,s);
if (strlen(s) > 0) strncpy(lClient,s,3);
do { INS("li","user","user",6,35,s); } while (s[0]==0);
if (strlen(s) > 0) strncpy(lUser,str2upper(s),12);
do { getpassword(s,sizeof(s)); if (s[0]=='?') help("li","password",""); } while ((s[0]=='?')||(s[0]==0));
if (strlen(s) > 0) strncpy(lPassword,str2upper(s),10);
INS("li","language","language [EN]",6,35,s);
if (strlen(s) > 0) strncpy(lLanguage,str2upper(s),1);
INS("li","mode","mode [R/3]/R/2",6,35,s);
if (strlen(s) > 0) strncpy(lMode,s,3);
if (strcmp(lMode,"R/2")==0) {
do { INS("li","gateway host","gateway host [clr3e10 ]",6,35,s); } while (s[0]==0);
if (strlen(s) > 0) strncpy(lGwhost,s,30);
do { INS("li","gateway service","gateway service [sapgw10 ]",6,35,s); } while (s[0]==0);
if (strlen(s) > 0) strncpy(lGwservice,s,30); }
else {
INS("li","hostname","hostname [clr3e10]",6,35,s);
if (strlen(s) > 0) strncpy(lHostname,s,30);
INS("li","system number","system number [10]",6,35,s);
if (strlen(s) > 0) strncpy(lSysnr,s,2);
INS("li","gateway host","gateway host [clr3e10]",6,35,s);
if (strlen(s) > 0) strncpy(lGwhost,s,30);
INS("li","gateway service","gateway service [sapgw10 ]",6,35,s);
if (strlen(s) > 0) strncpy(lGwservice,s,30); }
INS("li","trace","trace on/[off]",6,35,s);
if (strlen(s) > 0) strncpy(lTrace,s,3); NL;
/* logon settings */
RfcOptions->destination = lDestination;
RfcOptions->client = lClient;
RfcOptions->user = lUser;
RfcOptions->password = lPassword;
RfcOptions->language = lLanguage;
if (strcmp (lMode,"R/2")==0) {
RfcOptions->mode = RFC_MODE_CPIC;
if (lGwhost[0] == 0) RfcConnoptCpic->gateway_host = NULL;
else RfcConnoptCpic->gateway_host = lGwhost;
if (lGwservice[0] == 0) RfcConnoptCpic->gateway_service = NULL;
else RfcConnoptCpic->gateway_service = lGwservice;
RfcOptions->connopt = RfcConnoptCpic; }
else {
RfcOptions->mode = RFC_MODE_R3ONLY;
if (lHostname[0] == 0) RfcConnoptR3only->hostname = NULL;
else RfcConnoptR3only->hostname = lHostname;
if (lSysnr[0] != 0) RfcConnoptR3only->sysnr = atoi(lSysnr);
if (lGwhost[0] == 0) RfcConnoptR3only->gateway_host = NULL;
else RfcConnoptR3only->gateway_host = lGwhost;
if (lGwservice[0] == 0) RfcConnoptR3only->gateway_service = NULL;
else RfcConnoptR3only->gateway_service = lGwservice;
RfcOptions->connopt = RfcConnoptR3only; }
if ((0 == strcmp(lTrace,"on"))||(0==strcmp(lTrace,"ON"))) RfcOptions->trace = 3;
else RfcOptions->trace = 0;
/* open connection */
OUT("Opening...",4); NL; hRfc = RfcOpen(RfcOptions); LOG(hRfc,"RfcOpen called","");
return hRfc;
}
void WIN_DLL_EXPORT_FLAGS rfc_error(char *operation)
{
#ifdef SAPonNT
char s[16];
#endif
RFC_ERROR_INFO RfcErrorInfo;
OUT("RFC error",0);
OUTS("operation/code",0,15,operation);
memset(&RfcErrorInfo,0,sizeof(RfcErrorInfo));
RfcLastError(&RfcErrorInfo);
OUTS("key",0,15,RfcErrorInfo.key);
OUTS("status",0,15,RfcErrorInfo.status);
OUTS("message",0,15,RfcErrorInfo.message);
OUTS("internal status",0,15,RfcErrorInfo.intstat); NL;
RfcClose (RFC_HANDLE_NULL);
#ifdef SAPonNT
INS("","","Quit? [y]",4,24,s);
#endif
exit(1);
}
/*
------------------------------------------------------------------------
Call function Y_SD_COA_SHIPINFO_DOWN
exporting
IN_VBELN structure VBELN length 10 number of fields 1
importing
OUT_SHIPREC structure YSD_COASHP length 475 number of fields 34
tables
exceptions
------------------------------------------------------------------------
*/
RFC_RC WIN_DLL_EXPORT_FLAGS y_sd_coa_shipinfo_down(RFC_HANDLE hRfc
,VBELN *eInVbeln
,YSD_COASHP *iOutShiprec
,char *xException)
{
/* RFC variables */
RFC_PARAMETER Exporting[2];
RFC_PARAMETER Importing[2];
RFC_TABLE Tables[1];
RFC_RC RfcRc;
char *RfcException = NULL;
/* install structures */
if (handleOfVBELN==0) {
RfcRc = RfcInstallStructure("VBELN",
typeOfVBELN,
ENTRIES(typeOfVBELN),
&handleOfVBELN);
if (RfcRc != RFC_OK) rfc_error("RfcInstallStructure"); }
if (handleOfYSD_COASHP==0) {
RfcRc = RfcInstallStructure("YSD_COASHP",
typeOfYSD_COASHP,
ENTRIES(typeOfYSD_COASHP),
&handleOfYSD_COASHP);
if (RfcRc != RFC_OK) rfc_error("RfcInstallStructure"); }
/* define export params */
Exporting[0].name = "IN_VBELN";
Exporting[0].nlen = 8;
Exporting[0].type = handleOfVBELN;
Exporting[0].leng = sizeof(VBELN);
Exporting[0].addr = eInVbeln;
Exporting[1].name = NULL;
Tables[0].name = NULL;
/* call function module */
RfcRc = RfcCall(hRfc,"Y_SD_COA_SHIPINFO_DOWN",Exporting,Tables);
LOG(hRfc,"RfcCall called","");
switch (RfcRc) {
case RFC_OK :
/* define import params */
Importing[0].name = "OUT_SHIPREC";
Importing[0].nlen = 11;
Importing[0].type = handleOfYSD_COASHP;
Importing[0].leng = sizeof(YSD_COASHP);
Importing[0].addr = iOutShiprec;
Importing[1].name = NULL;
/* receive results */
RfcRc = RfcReceive(hRfc,Importing,Tables,&RfcException);
LOG(hRfc,"RfcReceive called","");
switch (RfcRc) {
case RFC_SYS_EXCEPTION : strcpy(xException,RfcException);
case RFC_EXCEPTION : strcpy(xException,RfcException); }
}
return RfcRc;
}
RFC_RC WIN_DLL_EXPORT_FLAGS cll_y_sd_coa_shipinfo_down(RFC_HANDLE hRfc)
{
/*
---------------------------------------------------
begin of caller example code
replace the example code with your code
---------------------------------------------------
*/
/* RFC variables */
static RFC_RC RfcRc;
char s[1024];
/* param variables */
VBELN eInVbeln;
YSD_COASHP iOutShiprec;
char xException[256];
char x[276];
help("f", "", "");
INS("i","","Input? [y]/n",4,24,s); NL;
while ((s[0]!='n') && (s[0]!='N')) {
/* init export parameters */
SETCHAR(eInVbeln.Vbeln,"");
/* input export parameters */
OUT("exporting",6);
OUT("IN_VBELN",8); NL;
do { INS("esi","IN_VBELN","Fill structure? y/n",4,24,s); } while (s[0]==0); NL;
if ((s[0]=='y')||(s[0]=='Y')) {
INS("esfi","IN_VBELN","VBELN",10,30,s); SETCHAR(eInVbeln.Vbeln,s);
OUT("IN_VBELN",8); NL; }
INS("c","","Call? [y]/n",4,24,s); NL;
if ((s[0]!='n') && (s[0]!='N')) { OUT("Calling...",4); NL;
/* call RFC function */
RfcRc = y_sd_coa_shipinfo_down(hRfc
,&eInVbeln
,&iOutShiprec
,xException);
switch (RfcRc) {
case RFC_OK :
/* display importing parameters */
OUT("importing",6);
OUT("OUT_SHIPREC",8); NL;
INS("iso","OUT_SHIPREC","Display structure? [y]/n",4,24,s); NL;
if ((s[0] != 'n')&&(s[0] != 'N')) {
GETCHAR(iOutShiprec.Yyshipno,s);
OUTS("YYSHIPNO",10,30,s);
GETCHAR(iOutShiprec.Yyship1,s);
OUTS("YYSHIP1",10,30,s);
GETCHAR(iOutShiprec.Yyship2,s);
OUTS("YYSHIP2",10,30,s);
GETCHAR(iOutShiprec.Yyship3,s);
OUTS("YYSHIP3",10,30,s);
GETCHAR(iOutShiprec.Yyship4,s);
OUTS("YYSHIP4",10,30,s);
GETCHAR(iOutShiprec.Yyship5,s);
OUTS("YYSHIP5",10,30,s);
GETCHAR(iOutShiprec.Yyship6,s);
OUTS("YYSHIP6",10,30,s);
GETCHAR(iOutShiprec.Yycarcod,s);
OUTS("YYCARCOD",10,30,s);
GETBCD(iOutShiprec.Yycomlbs,s, 2);
OUTS("YYCOMLBS",10,30,s);
GETBCD(iOutShiprec.Yycodfee,s, 2);
OUTS("YYCODFEE",10,30,s);
GETBCD(iOutShiprec.Yycodto,s, 2);
OUTS("YYCODTO",10,30,s);
GETBCD(iOutShiprec.Yyvarlbs,s, 2);
OUTS("YYVARLBS",10,30,s);
GETCHAR(iOutShiprec.Yynull01,s);
OUTS("YYNULL01",10,30,s);
GETNUM(iOutShiprec.Yyphone,s);
OUTS("YYPHONE",10,30,s);
GETCHAR(iOutShiprec.Yypickby,s);
OUTS("YYPICKBY",10,30,s);
GETCHAR(iOutShiprec.Yypackby,s);
OUTS("YYPACKBY",10,30,s);
GETCHAR(iOutShiprec.Yysentby,s);
OUTS("YYSENTBY",10,30,s);
GETCHAR(iOutShiprec.Yyautinv,s);
OUTS("YYAUTINV",10,30,s);
GETCHAR(iOutShiprec.Yynull02,s);
OUTS("YYNULL02",10,30,s);
GETDATE(iOutShiprec.Yyshipdt,s);
OUTS("YYSHIPDT",10,30,s);
GETCHAR(iOutShiprec.Yyswtrk,s);
OUTS("YYSWTRK",10,30,s);
GETDATE(iOutShiprec.Yyspdate,s);
OUTS("YYSPDATE",10,30,s);
GETTIME(iOutShiprec.Yysptime,s);
OUTS("YYSPTIME",10,30,s);
GETDATE(iOutShiprec.Yyinvdat,s);
OUTS("YYINVDAT",10,30,s);
GETCHAR(iOutShiprec.Yyinvno,s);
OUTS("YYINVNO",10,30,s);
GETCHAR(iOutShiprec.Yyproces,s);
OUTS("YYPROCES",10,30,s);
GETBCD(iOutShiprec.Yycrdfee,s, 2);
OUTS("YYCRDFEE",10,30,s);
GETCHAR(iOutShiprec.Yyshpwo,s);
OUTS("YYSHPWO",10,30,s);
GETCHAR(iOutShiprec.Yyshpws,s);
OUTS("YYSHPWS",10,30,s);
GETCHAR(iOutShiprec.Yyshpwcc,s);
OUTS("YYSHPWCC",10,30,s);
GETCHAR(iOutShiprec.Yybillto,s);
OUTS("YYBILLTO",10,30,s);
GETCHAR(iOutShiprec.Yydlrpo,s);
OUTS("YYDLRPO",10,30,s);
GETCHAR(iOutShiprec.Yymoney,s);
OUTS("YYMONEY",10,30,s);
GETCHAR(iOutShiprec.Yydlrcod,s);
OUTS("YYDLRCOD",10,30,s);
OUT("OUT_SHIPREC",8); NL; }
break;
case RFC_EXCEPTION :
/* exception raised */
OUT("exception",6);
do { sprintf(x,"%s raised. Help? ?/[n]",xException); INS("xo",xException,x,8,42,s); } while (s[0]=='?'); NL;
break;
case RFC_SYS_EXCEPTION : rfc_error("system exception raised");
case RFC_FAILURE : rfc_error("failure");
default : rfc_error("other failure");
}
}
do { INS("a","","Again? y/n",4,24,s); } while (s[0]==0); NL;
}
/*
---------------------------------------------------
end of caller example code
---------------------------------------------------
*/
return RfcRc;
}
/*
------------------------------------------------------------------------
main program
------------------------------------------------------------------------
*/
main(int argc, char **argv)
{
/* RFC variables */
static RFC_OPTIONS RfcOptions;
static RFC_CONNOPT_CPIC RfcConnoptCpic;
static RFC_CONNOPT_R3ONLY RfcConnoptR3only;
static RFC_ENV RfcEnv;
static RFC_HANDLE hRfc;
static RFC_RC RfcRc;
static char d;
char s[1024];
int count;
/* program arguments */
outfile = NULL; infile = NULL; logfile = NULL;
for (count=0;count
|
|
|
|
|
first, a polite criticism: nobody is ever going to look at that much code.
anyway, unless you are writing a COM server DLL, you don't need to use RegSvr32 to "register" it.
specifically, RegSvr32 loads your DLL and tried to call a function called "RegisterServer" in your DLL; RegisterServer usually sets up a bunch of registry stuff that lets COM know what your DLL does. but, if you're not writing a COM server DLL, there's no need to have a RegisterServer function and no need to use RegSvr32.
-c
Software | Cleek
|
|
|
|
|
Hi ! Here is my software.
I have a main worker thread which is the Test Plan.
This worker thread create other sub-worker threads as Test Case. Everything work fine but I have problems with the refresh of my view. My threads (almost all the software) is part of a document (I use doc-view architecture of MFC).
I use icones to show if the test succeed or fail and also other pictograms.
Anyway, I WANT TO REFRESH MY SCREEN WITH UpdateAllViews() which call in some way the OnDraw function).
I have ASSERT fail because it is likely that I have passed a C++ object from one thread to another. I don't really understand the explanation associated in the Wincore.CPP file.
How I can refresh my screen (anytime, when I want) without having problem in a Multithread software ???
Thank you !
|
|
|
|
|
One way is to use PostMessage(...).
UINT MyThread(LPVOID pParam)
{
CMyView *pView = (CMyView *)pParam;
pView->PostMessage(WM_MY_UPDATE_MESSAGE, wParam, lParam);
}
...
...
...
ON_MESSAGE(WM_MY_UPDATE_MESSAGE, OnMyUpdateMessage)
...
...
...
LRESULT CMyView::OnMyUpdateMessage(WPARAM wParam, LPARAM lParam)
{
UpdateAllViews();
}
|
|
|
|
|
Hi,
I was using this code to read from text log files, and it all worked fine:
<br />
CFile log_file;<br />
CString log_line;<br />
log_file.Open(_T("file"),CFile::modeRead|CFile::shareDenyNone);<br />
CArchive ar (&log_file,CArchive::load);<br />
<br />
while (ar.ReadString (log_line))<br />
{<br />
}<br />
<br />
ar.Close<br />
file.Close<br />
What happens now, is that I use the same code,but within a thread, and from some reason, if I leave my application open (even when I am done reading the file), other applications can't delete the log files unless I close my app....
Any idea ?
Shay
|
|
|
|
|
Check the thread. Does it every exit the loop?
Kuphryn
|
|
|
|
|
yes it does, it even closes the file.
The thread posts a message to the GUI that it's done and it all works fine...
Any more ideas ?
|
|
|
|
|