opening .h files with a running program

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

opening .h files with a running program

Postby ZER0 » Wed Nov 18, 2009 12:31 pm

I need to create a program, which could open custom .h files and then use them afterwards. For now, i just tried #include "something.h" and it seems to work like i want. Can i just use opened .h file's path/file name for including it or i need to recompile project after opening a file? Would be grateful for any info on this topic..
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby arisme » Wed Nov 18, 2009 1:18 pm

ZER0 wrote:I need to create a program, which could open custom .h files and then use them afterwards. For now, i just tried #include "something.h" and it seems to work like i want.
.
You can 'include any file you want. It will be loaded and become part of the compiled application's environment. Its contents will be available to the unit that loaded it.

The only requirement is that the compiler can read and recognize the contents without any syntax or other problems.

ZER0 wrote:Can i just use opened .h file's path/file name for including it...

No path - just the file name. The search path is either current directory, or the directories set as a search path in Project Options.

.e.g.
Code: Select all
#include "A_Header_file.h"
     //  loaded from the current directory

#include <Another_file.hpp>
     //  loaded from the search path directories (set in Project Options)
     //  search starts in current directory, and then each of the search
     //  path directories in turn until file is found


ZER0 wrote:...or i need to recompile project after opening a file?

Whenever you change the contents of the #include list (by adding or removing file names, or changing any of their contents), you will need to recompile, so that the application is built with the new #include list. Unless you recompile, your applicatiion's .exe file will remain as it was before the changes.

Any changes you make in the Code Editor will not become effective until you have recompiled.

Aris
arisme
BCBJ Master
BCBJ Master
 
Posts: 357
Joined: Thu Jun 07, 2007 9:35 pm
Location: UK

Re: opening .h files with a running program

Postby ZER0 » Wed Nov 18, 2009 2:17 pm

Whenever you change the contents of the #include list (by adding or removing file names, or changing any of their contents), you will need to recompile, so that the application is built with the new #include list. Unless you recompile, your applicatiion's .exe file will remain as it was before the changes.
Any changes you make in the Code Editor will not become effective until you have recompiled.


Well, i need to change #include list when my program is running, i mean not using c++ builders code editor or something. Is there any way to assign a variable to included files list, which would define the file name i've opened using the running program?

The program should open one custom .h file while running, and use its content for calculations. Each of these files contain one function defined in the same way, just the calculations are different for each one. I need to get outputs of the function, but i cannot include more than one at once because the function definition is the same. I hope my situation is clearer now.
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby arisme » Wed Nov 18, 2009 7:41 pm

ZER0 wrote:I hope my situation is clearer now.

I hope so - we can only provide useful answers if we can understand what the requirement is.

What I see at the moment is that you have a function that does some calculations. Let's call it the Calculating Function for the moment.

Your application wants to feed the Calculating Function several different sets of data to use for its calculations.

If that is the case, then the #include approach is the wrong way to do things. The #include mechanism will introduce data that can be used by functions for calculations - but it is intended to provide the data for the construction of the application, not for dynamic supply of fresh data at runtime.

There are many different ways of introducing fresh data into your application when it is running. Which one is most suitable depends on the nature and detail of the tasks that the application is performing.

In your case, Data sets for your Calculating Function could be provided in one or more of the following ways:-

1. The program loads one or more files each containing one or more Data sets.
2. The application has a user interface, and the user enters each Data set as required.
3. The Data sets already exist somewhere in the computer memory (e.g. the Registry) and the application reads the data in from there.
4. The application is built with all the possible Data sets already contained in it, and each Data set is fed to the Calculating Function as required.
5. The Data sets contain values used or generated by the operating system, and you use Windows API calls to retrieve them.

Which of the above approaches is best suited for your requirement depends mostly on the detail of your Calculation Function and the nature and origin of the Data sets.

I am sorry if this seems to be confusing, and too many choices. In the BCB world, there are often several different ways to satisfy a particular requirement. Sometimes the difficult choice is not how to do something, but which of several approaches to use.

In your case, there happens to be a wide range of choices. We can home in on a suitable way of achieving your objective, if you can supply some detail about your applications.

(A) Imagine I am a user sitting at your computer, with your application running. What do I do, and what does your application do in response?

(B) What is contained in your Data sets? Numeric values? Strings?

(C) Where do your Data sets come from - how are they created?

Aris
arisme
BCBJ Master
BCBJ Master
 
Posts: 357
Joined: Thu Jun 07, 2007 9:35 pm
Location: UK

Re: opening .h files with a running program

Postby ZER0 » Thu Nov 19, 2009 4:52 am

(A) Imagine I am a user sitting at your computer, with your application running. What do I do, and what does your application do in response?


First of all, those functions are something like void function(input char, output char,input length, output length). Input and output are chars which contain binary numbers. Input and output length can be provided so you can use less than maximum length.

As a user, you browse and select function file which will be used for calculations. Then, program generates a matrix which is formed according to the outputs it gets when scrolling through all possible function inputs.

(B) What is contained in your Data sets? Numeric values? Strings


Some function calculations which return string of binary numbers as output.

(C) Where do your Data sets come from - how are they created?


Well, i have been provided with a set of theese .h files, i could include them all for now, by changing the function names, but the point is to make it possible to add more functions if needed in future.

Hope we are getting somewhere, thanks for your time.
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby arisme » Thu Nov 19, 2009 9:15 pm

ZER0 wrote:As a user, you browse and select function file which will be used for calculations. Then, program generates a matrix which is formed according to the outputs it gets when scrolling through all possible function inputs.

Thanks for the info.

The project sounds like a fairly typical application.

If I have it right, you have some header files, and your objective is to create an application that behaves as described above.

Do you have any other files apart from the headers?

ZER0 wrote:Well, i have been provided with a set of theese .h files, i could include them all for now, by changing the function names,...

It would be useful to know whether the header files are normal BCB types, or whether there is something special about them. Choose one that is representative, replace the function names with "xxxxx", and enclose the text with the [code][/code] delimiters in your post.

ZER0 wrote:...but the point is to make it possible to add more functions if needed in future.

We will cover that later when we know how to get the basic application working. We still need some more details before we can suggest a suitable path through the many choices.

ZER0 wrote:Hope we are getting somewhere,...

Yes we are, but in this case we have to start with establishing what we have available to work with. This can be a step by step process sometimes.

Aris
arisme
BCBJ Master
BCBJ Master
 
Posts: 357
Joined: Thu Jun 07, 2007 9:35 pm
Location: UK

Re: opening .h files with a running program

Postby ZER0 » Fri Nov 20, 2009 2:56 am

The project sounds like a fairly typical application.

Yes, its quite typical at this stage, but there will be more requirements and functionality added later, for now, its just as i wrote before. Although i need to resolve this matter to proceed.

Do you have any other files apart from the headers?

No, i don't.

It would be useful to know whether the header files are normal BCB types, or whether there is something special about them.

Those headers seem to be c++, not c++ builder files in code, but i think it can be made compatible easily.

Code: Select all
void function(char *gg,char *og,int in,int on,int *ok)
{
int e10,e11,e16,e19;
// input 5, output 2
  int ag[5],od[2],ii,m1=1;
*ok=1;
for(ii=0;ii<in;ii++)
  if(*(gg+ii)=='0')
   *(ag+ii)=0;
  else
   *(ag+ii)=1;
e10=m1-(*ag&*(ag+2));
e11=m1-(*(ag+2)&*(ag+3));
e16=m1-(e11&*(ag+1));
e19=m1-(e11&*(ag+4));
*od=m1-(e10&e16);
*(od+1)=m1-(e16&e19);

for(ii=0;ii<on;ii++)
  if(*(od+ii)==0)
   *(og+ii)='0';
    else
   *(og+ii)='1';
}


The commented input and output row is just for info of what max input and output lengths can be. This is the most simple .h file i've got, but other functions only differ at input/output quantity and size, using same descriptions.

Awaiting for further replies.. :)
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby arisme » Fri Nov 20, 2009 1:55 pm

Thanks for the additional information.

Please forgive me if I am wrong, but I have the impression that you are a newcomer to C++Builder, maybe to C/C++ programming, and maybe even to programming.

Can you give us some idea of the level of your skills and experience in computing?

The reason for the question is that sometimes a response to a person with a requirement can be as short as one sentence. To an experienced programmer, that sentence provides all the information he needs to satisfy his requirement. To a beginner, that sentence may be a waste of time because he does not have the skills or experience to understand what is being communicated to him.

I normally try to match my responses to the perceived capabilities of the person asking for help. This is not easy to get right because we start with no knowledge of the respondent at all, and gradually learn about each other through an exchange of posts.

In your case at the moment, I am not all sure how to frame my responses so that they are useful to you, and do not create more problems than they solve.

Aris
arisme
BCBJ Master
BCBJ Master
 
Posts: 357
Joined: Thu Jun 07, 2007 9:35 pm
Location: UK

Re: opening .h files with a running program

Postby ZER0 » Fri Nov 20, 2009 5:08 pm

Can you give us some idea of the level of your skills and experience in computing?

Well, i'm quite new to a programming and c++ builder. All the projects i've done using c++ builder were for my studies, so they were not complex mostly. Usually i get stuck at technical things because i lack experience, like this time, but i guress i dont ahve any problems with a logical parts of the code.

In your case at the moment, I am not all sure how to frame my responses so that they are useful to you, and do not create more problems than they solve.

I understand what you mean. Try not to get to the very basics...
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby arisme » Sat Nov 21, 2009 7:36 pm

The code you posted previously is a function body. In C++, BCB and VCL, function bodies normally reside in the unit files with a .cpp extension. Files with an .h extension normally only contain function prototypes, which the compiler uses to construct the program. How and why your function bodies came to be contained in *.h files is a puzzling question - which we will not pursue at the moment.

You could add all your existing functions into your application and present the user with a list of available functions to choose from. Everything that the program might want to use in the course of its execution will already be there and compiled in.

This is the normal state of affairs in the Windows / BCB / VCL world. You can extend the functionality, but then a new build is required.

I have just had an idea on how we might be able to add new functions without recompiling, but I will need to check out some things in a testbed to see if it is feasible. I have a heavy workload at the moment, so this will take some time. I will come back in due course.

In the meantime, you might want to construct your application with all the functions available to you.

Aris
arisme
BCBJ Master
BCBJ Master
 
Posts: 357
Joined: Thu Jun 07, 2007 9:35 pm
Location: UK

Re: opening .h files with a running program

Postby theLizard » Sat Nov 21, 2009 10:52 pm

I will stick my neck out a little here and assume that you are wanting your application to run like a runtime interpreter akin to a 4gl language that reads external files somewhat like a script file that defines the execution and produces the final output based on the contents of the script (.h) file.

Rather than call the file a .h file, call it a script file, there would be less confusion doing so and it would make it a lot easier to get the answers from more qualified readers you are after.

In the past I wrote an application that interpreted a script file which then produced the source code for a c# application, I believe that you are after something of a similar nature, not to produce source code but to return calculated values after reading in the parameters.

for example,

a script file may contain the following, I will call it code.
Code: Select all

make window
  name = [newWindow]
  caption = [New Window]
  position 20, 20
  width 100
  height 200
end window



the runtime interpreter reads this file and create a window using say, CreateWindowsEx(...) in the position specified.

If I am way of base let me know.
theLizard
BCBJ Guru
BCBJ Guru
 
Posts: 186
Joined: Wed Mar 18, 2009 2:14 pm

Re: opening .h files with a running program

Postby ZER0 » Sun Nov 22, 2009 4:06 am

You could add all your existing functions into your application and present the user with a list of available functions to choose from. Everything that the program might want to use in the course of its execution will already be there and compiled in.

That's what i've been doing in the meantime.

In the past I wrote an application that interpreted a script file which then produced the source code for a c# application, I believe that you are after something of a similar nature, not to produce source code but to return calculated values after reading in the parameters.

I believe you're right. These files can be called script files, extension is not really important here i think. The point is to use the functions described. If you have any suggestions how to use these .h files like a script files, that would also solve my problem.
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby theLizard » Sun Nov 22, 2009 3:45 pm

ZER0 wrote:I believe you're right. These files can be called script files, extension is not really important here i think. The point is to use the functions described. If you have any suggestions how to use these .h files like a script files, that would also solve my problem.


As I do not know what your sample function is / does I do not know how to help you with achieving your goals for example

e10=m1-(*ag&*(ag+2));

we know what e10, m1 and ag are

we know that the result of m1-(*ag&*(ag+2)) is assigned to e10

but we don't know how this (*ag&*(ag+2)) should be handled ie.

what does this mean *ag&* mean and what does this mean (ag+2) in relation to *ag&*

are we trying to say ag is a pointer!
does & in this equation mean and address to something!
does the * at the end mean to multiply the result of (ag+2)!

If we know how these should be translated then maybe we can begin to develop a way for your application to deal with the request you are making of us.

e10=m1- would be easy enough to handle as long as we know that these will be constant variable names or key words in any of the script files you are likely to encounter.

The following is part of a script file relating to the app which creates C# source code (for a specific job)

Code: Select all
  ///ignore comments
  ///* db field value assigned to form control field ie text boxes
  ///<className> <dbFieldName> <frmControl>
  ///<className> = class creatd based on db Table Name and formatted _tablename
  ///<dbFieldName>  database field
  ///<frmControl>   aspx: TextBox other
  ///TO DO: scripted function names.  ie function:{assign<className>FieldValues(_<className> <className>}
  /// <function> public bool assign<className>FieldValues(_<className> <className>)
<bh classAssignFieldValues>
//---------------------------------------------------------------------------
public bool assign<className>FieldValues(_<className> <className>)
  {
  //-----------------------------------------------------------------
  // page controls to tableClass members assignment
  // <Class.ClassMember> = <Control.???>
  // generated by CodeDjin " + <date>
  //-----------------------------------------------------------------
  <className>.success = true;
  <do><className>.<dbFieldName> = (!=)frmControl)

  <stop>
  return(<className>.success);
  }
<eh> //======================================================================


This code translates the above script and produces the C# code. (There is no doubt in my mind that this could be done more efficviently)

Code: Select all
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mnuClassMemberAssignmentClick(TObject *Sender)
  {
  if(!app._frmDb)
    return;
  int i, j;
  AnsiString s;
  TStringList* sl = new TStringList();
  src->LoadFromFile(ExtractFilePath(Application->ExeName) + "stringGenerator.src.txt");

  // generate code to assign textbox values to tableClass.members

    if(!canContinue())
      return;
  if(frmDb->cbTables->Items->Count >0 )
    {
    if(frmDb->cbTables->ItemIndex != -1)
      className = getClass(frmDb->cbTables->Items->Strings[frmDb->cbTables->ItemIndex]);
    }

  i=0;
while(src->Strings[i].Pos("classAssignFieldValues") !=0)  //loop through until end of header <stop> //detected
   i++;  //increment until found

while(src->Strings[i].Pos("<stop>") ==0) //do until stop found
  {
  if(src->Strings[i].Pos("<date>") != 0)
    src->Strings[i] = Replace(src->Strings[i],"<date>", "date");

  if(src->Strings[i].Pos("<do>") != 0) //not end of function
    process(src->Strings[i], sl );   //see function bellow...

  if(src->Strings[i].Pos("<className>") != 0)
    src->Strings[i] = Replace(src->Strings[i],"<className>", className);

  if(src->Strings[i].Pos("<eh>") != 0) //not end of function
    break;

  if(src->Strings[i].Pos("<do>") == 0) //not end of function
    {
    if(src->Strings[i].Pos("///") == 0)
      sl->Add(src->Strings[i]);
    else
      i++;
    }
  i++;  //move to next src line
  }

  while(src->Strings[i].Pos("<eh>") == 0)  //loop through until end of header <stop> //detected
    {
    if(src->Strings[i].Pos("<className>") != 0)
      src->Strings[i] = Replace(src->Strings[i],"<className>", className);
    if(src->Strings[i].Pos("<stop>") == 0)
      sl->Add(src->Strings[i]);
    if(i != src->Count)
      i++;
    }
  activeFile = className + "_assign.aspx.cs";
//  }
  makeShowFields(sl);
  resetClassValues(sl);
  toArrayClass(sl);
  createSession(sl);
//create notebook page
  r[addNoteBookPage(className+ "_assign", ".aspx.cs")]->Text = sl->Text;
  if(sl)
    delete sl;
  }

//---------------------------------------------------------------------------
AnsiString __fastcall TfrmMain::process(AnsiString s, TStringList *sl)
  {
  AnsiString a;// = line;
  int pos, j;

  pos = s.Pos("<do>");  //is it prototype instruction
  arrayIndex = false;

  if(s.Pos("<count>") !=0)
    arrayIndex = true;
  AnsiString token = "<className>";
  if(pos != 0)
    s = s.Delete(pos, 4);

  for(j=1; j<frmDb->lbField->Items->Count; j++)
    {
    dbFieldType = frmDb->lbDataTypes->Items->Strings[j];          //database field type
    dbFieldName = frmDb->lbField->Items->Strings[j]    ;            //database field name
    frmControl = setFormControl(frmControls->lbTBOrder->Items->Strings[j]);
    frmControlType = setFormControlType(frmControls->lbTBOrder->Items->Strings[j]);
    // r_Property.dateListed = con.get(\"dbFieldName\")DateTime.Parse();"

    pos = s.Pos("<className>");
    if(pos !=0)
      {
      a = s; //will be - > <className>.dbFieldName = (!=)frmControl

      a = ReplaceToken(a, token, className);  //
      a = ReplaceFieldName(a, dbFieldName);
      pos = a.Pos("(!=)");
      if( pos != 0)
        {
        a = iReplace(a, "(!=)");
        a = stringReplaceType(a, frmControlType, dbFieldName);
        }
      else
        a = stringReplaceType(a, frmControlType, dbFieldName);
        //should end up like - > r_Property.dateListed = DateTime.Parse(teDate.Text);
        //           or like - > r_Property.dateListed = teDate.Text;
      if(arrayIndex)
        {
        pos = a.Pos("<count>");
        a.Delete(pos, 7);
        a.Insert(IntToStr(j-1), pos);
        }
      sl->Add(a);
      }
    }
   }



One thing you should know regarding my example is that the script file and the code to translate the script required that an aspx (html) page be read in to determine the web controls on the page.

I hope you understand what I am saying, there is little that cannot be done by computers, if you can tell it how to do it, it WILL do it.

help us understand your script so that we can help you.
theLizard
BCBJ Guru
BCBJ Guru
 
Posts: 186
Joined: Wed Mar 18, 2009 2:14 pm

Re: opening .h files with a running program

Postby ZER0 » Mon Nov 23, 2009 10:01 am

I was only given these .h files, with no detailed description on how they work. I only know that:
Code: Select all
void function(char *gg,char *og,int in,int on,int *ok)

char gg is an input char of length in, and char og is an output char of length on.

As i've tried to use one included .h file, it seems to be working correctly, giving outputs for a certain input.
ZER0
Active Poster
Active Poster
 
Posts: 15
Joined: Wed Nov 18, 2009 12:20 pm

Re: opening .h files with a running program

Postby theLizard » Mon Nov 23, 2009 2:10 pm

ZER0 wrote:char gg is an input char of length in, and char og is an output char of length on.

As i've tried to use one included .h file, it seems to be working correctly, giving outputs for a certain input.


I still need to know e10 gets the value from = m1-(*ag&*(ag+2)); can you find out if you do not know?

If we are not able to determine what this actually means there is no point continuing.

regards

theLizard.
theLizard
BCBJ Guru
BCBJ Guru
 
Posts: 186
Joined: Wed Mar 18, 2009 2:14 pm

Next

Return to Technical

Who is online

Users browsing this forum: No registered users and 4 guests

cron