Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to export the c-programmes?

Posted on 1999-07-14
4
Medium Priority
?
228 Views
Last Modified: 2010-04-15
I have a routine written in the c-programming lang which returns a string or value as a result. I want to provide interface to this routine using VB/VC++ so that when I press a button it should execute c programme i.e written, and should display the result in the dialog box. I know that for that c routine has to to "Publicly EXPORTED", but I don't how to do this? Please Help.
0
Comment
Question by:arvindhp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:arvindhp
ID: 1263623
If possible give the C-code.
0
 
LVL 3

Accepted Solution

by:
Norbert earned 150 total points
ID: 1263624
2 solutions are possible:
Write a DLL
or use COM/DCOM
If your program realy is a C program (not C++) COM/DCOM is verry hard to implement.
So in this case I would recommend the DLL solution.
As I know - until now I did not myself - the C Function has to be declared with calling convention stdcall and as exportable like
Inside *.C/*.H file
__declspec( dllexport ) YourReturnType  __stdcall YourFunction(YourParameter1Type Parameter1,...);
/*... for other parameters not for variable arguments*/
now the function - if compiled and linked without errors - is ready for external use:
from VC you need the header that declares
__declspec( dllimport ) YourReturnType  __stdcall YourFunction(YourParameter1Type Parameter1,...);
and the *.lib file that is generated by the linker or
LoadLibrary(...),GetProcAdress(...)

from VB you need to declare the function like
Public Declare YourFunction  Lib "YourLib" (Parameter1 as YourParameterType1,...) as YourReturnType

0
 

Author Comment

by:arvindhp
ID: 1263625
I have got only Turbo C++ compiler and VB with me(please assume). __stdcall and __export__ is not available with this compiler. Is there any other method available to do this kind of operation. If yes please give the method as well as code.
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1263626
First of all if an answer does not satisfy you or in this case seems not work for you you should not accept it.
if you accept it it is stored inside the previous asked question section an no other expert is able to answer you.
You have Turbo C - what you did not say - I have Visual C and no expirience with Turbo C. But I will try to help. may be you can figure out your self what you have to do if you got further information
First of all is the version of Turbo C able to build DLL's ?
if not you have no chance to do what you want.
if yes try to figure out how to export a function may be you have to use a *.def file - use online help keyword may be export(ing Functions from DLL)
I can show you what microsoft tells about stdcall calling convention
From the online help:
/* Start of text*/
Microsoft Specific ®

The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.

Element                                            Implementation
Argument-passing order                    Right to left.

Argument-passing convention          By value, unless a pointer or reference type is passed.

Stack-maintenance responsibility     Called function pops its own arguments from the stack.

Name-decoration convention           An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the
                                                        number of bytes (in decimal) in the
                                                        argument list. Therefore, the function declared as int func( int a,
                                                        double b ) is decorated as follows: _func@12

Case-translation convention            None
Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.

END Microsoft Specific
/*End of text*/
with this information you may be able to use borland online help to figure out how to declare the functions that VB can find them.
Keyword Calling convention
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question