Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Need to be able to a DLL (how/template to use)

I use the R&R (ReportWorks) report writer.  It has the ability to call a DLL, specify the functions and then pass a 8000 character buffer, returning the modified buffer and a T/F value as the return value.

I don't program in C and am looking for a template and instructions that I can use as a basis for creating a dll collection of some additional functions not available in R&R.  For example, do while/for next loops, building encryption routines, etc.

I have access to visual C Version 6 from Microsoft.

Does anyone have something that I can use as a template to learn how to start doing this.

The DLL would be a dynamic DLL loaded at runtime.  Please be thorough in your answer as I don't current program in C but can learn what is needed.  There would be no data access, only the passing of the 8000 character string buffer, parsing of parameters from the buffer, performance of string/math calculations, packing the results in the buffer and setting the return value.

Thanks,

Cliff.
0
cwsoft05
Asked:
cwsoft05
  • 5
  • 3
2 Solutions
 
cwsoft05Author Commented:
For a simple example,  pass a string in the following format.

0000110.00,0000120.00,0000130.00

Parse the value, this one has 3 but could have any number of string values, 0000110,00  0000120.00 0000130.00, convert to floating point numbers, add the 3 together together and divide by the number of values (i.e. compute the average) and put the average back into the string, and set the return value to .T.

Have a 2nd function in the same DLL that will return the largest value (max).

Thanks,  Cliff.
0
 
AlexFMCommented:
Open Visual Studio 6, select File - New - Project. Select Win32 Dll project type. On one of Project Wizard steps select "Dll which exports symbols".
When project is created, you can see that Wizard generated for you sample exported class, variable and function. Remove class and variable and use function. You can change function name and parameters according to your needs, add implementation code etc. New functions are added using the same syntax.
Dll create by Wizard contains h-file with function prototype, and cpp file with function implementation. Wnen you chane function and add new function, make changes in both files.
0
 
cwsoft05Author Commented:
Thanks for the info, any help taking the actual example into some source code.  It would help understanding the C approach.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fridomCommented:
I have no access to the given software, the only thing I can help you with is, how to build a DLL, someone else has pointed out to you what you have to do.

You just have to see that you "decorate" your exported functions either with

__declspec(dllexport) fun_return_value name_of_function(par1_type par1, par2_type par2 ) etc.

or that you write a .def file.

The information on how to build a DLL can be found in the MSDN documentation.

I posted an example on how to build and use a DLL here:
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21877640.html

That code will run with MSVC also.
Friedrich
0
 
cwsoft05Author Commented:
Thanks for the information.  I will ook at the above post.  

Why do you comment "I have no access to the given software"  I provided a sample in the 2nd post of what I was looking for.  This is application independent and does not need access to any software, other than for testing.

I don't program in C and wanted to limit how much time I need to spend learning to accomplish this little task.

The specs were simple.

Pass 8000 character string.
Parse the 3 strings, (i.e. until a comma or space) was encounterd
Convert the strings to a numeric value.
Add the 3 numbers together
Divide the intermediate result by the number of values parsed (i.e. don't use an average function)
Convert the result back to a string and pad to 8000 characters
put the 8000 character string back into the return buffer (same as the input buffer)
set the function return value to .T.
exit from the function.

The above is application indendent.

Cliff.
0
 
fridomCommented:
I just mentioned that I have not access to ReportWorks, of course I can build a DLL and yes it's qutie easy to write the function you are asking for, but I don't feel I have to do that for free.

The application is clear to me and I can give you a helping hand, but I won't write that all for you. There are just a few things you do not have mentioned:
- what happens if there are less then three numbers in the input buffer?


the prototyp for you functions should be

__declspec(dllexport) BOOL calculate_average_of_numbers_in (char * buf, size_t len_of_buf) {
 
For parsing the character in that function you can use
- strtok (to split the strign at , or ' '
- of you can use  prefabricated str_split function
- the conversion from char * to int can be done this way
can use sscanf (buf, "%d", &val) , or you can use the atol function for that
- adding is simply using +
- dividing is simply by using / (you probably have to use the number as a floating point number of a double
- converting back the result to a string is just
a sprintf(buf, "%d", num)

So that's all there is to do.

Regards
Friedrich

0
 
cwsoft05Author Commented:
Thanks for the information.  Experts Exchange does have a monthly cost to it so I don't consider that I am getting anything free from my point of view.  I am used to the community of assistance I receive from Xbase++ users.  They are more than willing to provide sample code for a simple function.  I have helped many users in the areas where I have expertise, but I don't have the same expertise in C,C++,etc.

As for examples, I have seen many lengthy examples provided in this forum so I did not thing I was asking for anything unusual or lengthy.  If I was asking more than I should that is my mistake, but the request appear reasonable.
0
 
fridomCommented:
It is I do not want to give you the impression you did not. But one has to sit down and writ the program the usual way you find code here is:
- someone posts code (that should be the OP)
- experts comment on it and change it

If the experts happens to have some code at hand he/she sometimes posted it.

However all the experts to that on their "free" time. So if you expect an pre-fabricated example just to use then thie migh or might happen.

Sometimes we sit down and writ the code from scratch, but there's no special incentive to do so also.

So here we go with the base code (minus every error handling for you request)
I won't build a DLL because that is not really hard to do:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

_Bool calculate_average (char * buf, size_t size_of_buf){
  long val1, val2, val3;
  double result;
 
  if (3 != sscanf(buf, "%ld %ld %ld", &val1, &val2, &val3)) {
    fprintf(stderr, "not a valid line giving up\n");
    return false;
  }
  result = (double) val1 + val2 + val3;
  result /= 3;
  /* clear out the buf */
  memset(buf, 0, size_of_buf);
  sprintf(buf, "%g", result);
  return true;
}





static char line[8000];

int main (void){
 
  strcpy(line, "1 2 3");
  calculate_average(line, sizeof(line));
  printf("average of 1 2 3 = %s\n", line);
 
  return 0;
 
}

Now I have give you all you need to do the rest yourself.

Regards
Friedrich
0
 
cwsoft05Author Commented:
Thank you.  If I had code, I would have posted it.  Thanks again very much for your efforts.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now