473,516 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

main app <-> module.so bi-direct access C / linux

2 New Member
Hi everyone!
I have some functions in main application (for example: log(), uppercase(), ...) and some in created module.so(counter() ...) But how can functions in module.so access to functions in main apllication ?

My first idea was create another module (util.so) and access module.so -> util.so. But that is nasty Too many modules ...

My next idea is send to the module.so pointers to functions which are in main app. But is normal or safe? Have functions log() and uppercase() static addresses while running main ?

Thanks for advice or any other ideas
Sep 11 '06 #1
2 2144
Banfa
9,065 Recognized Expert Moderator Expert
Are the *.so files the compiled objects

you can just declare extern any functions you wish to call from other modules

Expand|Select|Wrap|Line Numbers
  1.  
  2. // main.c
  3.  
  4. #include "main.h"
  5.  
  6. void log(char *msg)
  7. {
  8.   // write msg to file here
  9. }
  10.  
  11.  
  12. //  main.h
  13.  
  14. extern void log(char *msg);
  15.  
  16.  
  17. // module.c
  18.  
  19. voif fn(fn)
  20. {
  21.   log("Start of fn");
  22.  
  23.   // do something here
  24.  
  25.   log("end of fn");
  26. }
  27.  
Sep 11 '06 #2
netdrake
2 New Member
Uff, i not sure that we was understand :) Here is small code example:

/******* MAIN APPLICATION *****/
// main.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "main.h"


void logger(const char *message)
{
fprintf(stdout,message);
return;
}


int main(void)
{

char *error;
void *module;
void (*check)(const char*);

// open module.so
module = dlopen("module.so",RTLD_LAZY);
if(!module) { // error check
puts("Cannot open module.so");
exit(1);
}

//get symbol
check = dlsym(module,"check");
if ((error = dlerror()) != NULL) exit(1);

//call function in module ...
(*check)("234xxx3");

// close module.so
dlclose(module);

return 0;
}


//main.h
#ifndef __MAIN_H_
#define __MAIN_H_

void logger(const char *message);

#endif

/**************** MODULE.SO *************/
// module.c
#include "module.h"

void check(const char *string)
{
unsigned int found = 0;
unsigned int i = 0;


if(!string) return;

while(*(string + i)) {
if(*(string + i) < '0' || *(string + i) > '9')
found++;

i++;
}

if(found > 0) {
// I WANT CALL logger func which is in main application
// BUT HOW ? :) IS IT POSIBLE ?
// Here is a big problem with symbols... module.so doesnt known
// about logger func ..
// logger("error fount characters in number");
puts("Module.so: Error found characters in number");
}

return;
}

//module.h
#ifndef __MODULE_H_
#define __MODULE_H_

void check(const char *string);

#endif
Sep 11 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2369
by: Jonny T | last post by:
hi, i want to echo the string '<?php' in a php script like : echo "<?php"; but when i try nothing gets displayed ... if I use echo "<\?php";
7
5153
by: haoren | last post by:
Can anybody help me with this problem: How can I echo a string that contain <? and <?php? For example, $str="test <? and <?php echo"; echo $str;
3
1957
by: winderjj | last post by:
Hi All, I need everyones opinion. I am very new to XML but am temporarily putting all my efforts into using it. This is what I need to do. Write an xml parser (in C) that will parse a fairly complicated XML file that is full of technical data(most scalar values). Then I need to store all the info in a C structure. Could some people...
4
9625
by: matatu | last post by:
Hi to all, I have a xml file, a substring like: &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; which after an xslt trasform is rendered as (using xsl:output method html): &lt;a href="#"&gt;text&lt;/a&gt;
4
62087
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I supposed to write this function? String.replace(/</g,'&lt;');
5
3513
by: tobbe | last post by:
Hi Im trying to load a XmlDataDocument with the following xml: <ROOT> <NAME> &LT; &AMP; &GT; " '</NAME> </ROOT> And i know I have a entity problem here, but i cant find any solution for it. The problem is that i recive this from external source and cant
10
42925
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA...
4
1901
by: Armel Asselin | last post by:
Hello, I've been using XML for a while in a rather 'free' manner (i.e. as long as IE accept it it's OK), I read recently (again) the Xml standard 1.0 (3rd edition) and found this sentence: Well-formedness constraint: No < in Attribute Values The replacement text of any entity referred to directly or indirectly in an attribute value MUST...
4
1795
by: spibou | last post by:
I saw it at http://www.faqs.org/rfcs/rfc1305.html Is it not the same as writing ``if (m)'' ?
3
3987
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets written to my MySQL database. I can later view this data back in the form. One thing I've noticed happening is if I enter code such as &lt; it gets...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.