Thread: Need to know parameter format for a Call function?

  1. #31
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Will1 View Post
    Not derogatory, sarcastic! I gather from you posts that you are so absolutely convinced that modern Operating Systems are superior to any facet of older Operating Systems such as DOS that pointing out a facet where DOS is superior to modern Operating Systems went right over your head.
    In what way is any of the aspects you mentioned about DOS superior to modern systems? Direct hardware access? More like blatant disregard for security. That's what direct hardware access is. It is an implicit invitation to be malicious. I refuse to call that superiority. Memory segmentation? Real mode addressing is a thing of the past, and has been superseded by objectively better technology.

    Can you name a single property of DOS that is in any way better than a modern system like Windows or Linux?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  2. #32
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    This discussion seems to be all over the place. First, Will1 is talking about how much easier and better ADAM is than SQL. Next he's talking about low level data access. Developers and DBAs that deal with SQL never deal with that kind of low level access. The engine abstracts that all away and the developer simply uses it through a series of SQL commands. The implementation details are left to other specialists.

    So, are we really talking about ADAM vs. SQL (Structured Query Language) or are we talking about ADAM vs. particular implementation(s) of SQL engines/providers?

    This whole thing just smells of troll meat. The constant deflection and ambiguous statements. Specific examples and cites have been requested, but not provided. Ridiculous statements about the superiority of ancient operating systems that wouldn't even function on modern hardware. I'm done contributing to this until there's something substantial to respond to.
    If you understand what you're doing, you're not learning anything.

  3. #33
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    Quote Originally Posted by Elkvis View Post
    In what way is any of the aspects you mentioned about DOS superior to modern systems? Can you name a single property of DOS that is in any way better than a modern system like Windows or Linux?
    The ability to have more than one .data "segment" for one thing. Most of the people from back in the early days who tried OS/2 found it far better than WINDOWS. Unfortunately, IBM abandoned the PC market because they could see that the legal profession holds sway over all aspects of modern civilization. Lawyers in black robes have about wiped out the Bill of Rights that the founders of the once greatest nation that ever existed gave us. Despite that fact, innovators have managed to improve the condition of life but, having spent 75 years in this nation I can see that it is becomming so corroded by the legal profession that it will collapse before too much longer. I wonder why the mainframe has not been (completely) replaced by PCs? Could it be that the Operating Systems are far superior to PC Operating Systems?

  4. #34
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I'm done. I gave you my advice, but now you're talking politics and comparing PCs to mainframes, and just getting way off topic. Good luck!
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #35
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    Quote Originally Posted by itsme86 View Post
    This discussion seems to be all over the place. First, Will1 is talking about how much easier and better ADAM is than SQL. Next he's talking about low level data access. Developers and DBAs that deal with SQL never deal with that kind of low level access. The engine abstracts that all away and the developer simply uses it through a series of SQL commands. The implementation details are left to other specialists.

    So, are we really talking about ADAM vs. SQL (Structured Query Language) or are we talking about ADAM vs. particular implementation(s) of SQL engines/providers?

    This whole thing just smells of troll meat. The constant deflection and ambiguous statements. Specific examples and cites have been requested, but not provided. Ridiculous statements about the superiority of ancient operating systems that wouldn't even function on modern hardware. I'm done contributing to this until there's something substantial to respond to.
    Do you have a particular SQL application that you would like to try ADAM on? If not, I can send you an application that uses ADAM if you have a desktop computer. Don't know why but it doesn't seem to work on a laptop.

  6. #36
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Since you are targeting Win32, my advice is to put your interface into a proper dll interface - the same type of interface that the Win32 API ("kernel" api to the OS) uses. This will allow trivial access to your library in many languages.

    The suspected "only one file per process" issue may be solved using a "context" or "handle" abstraction. Your api's would then operate on the handles etc...

    In the MASM32 v11 SDK, there are dll examples (template code) in /examples/exampl01/dll/.

    Providing a C header file for your interface is also typical. Along with making it easy to consume in C/C++ code, it also documents your interface's ABI so that other languages know exactly how to use it.
    Here is what an initial template might look like:
    Code:
    // ADAM.h
    #ifndef ADAM_H
    #define ADAM_H
    
    #if defined(ADAM_IMPORT_LIB) /* if using an import lib for linking */
    #   define ADAM_API __declspec(dllimport)
    #else
    #   define ADAM_API
    #endif
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    /* these interfaces would be called once per process (or per thread if need be) */
    ADAM_API int __stdcall ADAM_Init();
    ADAM_API int __stdcall ADAM_Shutdown();
    
    /* allow for multiple "ADAM instances" to be created and manipulated independently */
    ADAM_API int __stdcall ADAM_CreatHandle(void *pStorage, unsigned __int64 nSize);
    
    ADAM_API int __stdcall ADAM_AddRecord(int handle, /* whatever */);
                        /* ADAM_XXX ... */
    
    #ifdef __cplusplus
    }/* extern "C" */
    #endif
    
    #endif //ADAM_H
    Also, if your interface uses any type of [asynchronous] callback mechanism, then allow the interface to accept stdcall function pointers for those callbacks.

    gg

  7. #37
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    Quote Originally Posted by Codeplug View Post
    Since you are targeting Win32, my advice is to put your interface into a proper dll interface - the same type of interface that the Win32 API ("kernel" api to the OS) uses. This will allow trivial access to your library in many languages.

    The suspected "only one file per process" issue may be solved using a "context" or "handle" abstraction. Your api's would then operate on the handles etc...

    In the MASM32 v11 SDK, there are dll examples (template code) in /examples/exampl01/dll/.

    Providing a C header file for your interface is also typical. Along with making it easy to consume in C/C++ code, it also documents your interface's ABI so that other languages know exactly how to use it.
    Also, if your interface uses any type of [asynchronous] callback mechanism, then allow the interface to accept stdcall function pointers for those callbacks.
    Thanks for getting back to the reason I originally posted this thread. I know you can "Push" an address onto the "Stack" in a C# program so the answer to my original, somewhat simple, question is ,"Can you push the address of an ADAM control block onto the Stack and issue a Call to a subroutine in C#?"

    The ADAM control block is fairly simple it consists of The File Name. the Operation Code, the Return Code, File Open/Closed indicator, The previous Operation Code, The Buffer address where records are passed to and from ADAM, The address of the Key or Record Number argument.

    Since an efficient ADAM file is created by a fairly complex formula, there is a program to create your ADAM file, ADAMCREA. You can load an ADAM file in ascending sequential order using subroutine ADAMALDM, or you can simply call the main ADAM subroutine ADAMACMD and add, access and/or erase records. You can read an ADAM file by key or record number, forward or backwards.

    The following is an example of an Assembly Language call to ADAM:

    Code:
              mov   ADAMOPCD,'O'                  ; Open Operation Code
              push  ADAMADDR                       ; Put address of ADAM control block on the stack
              call    ADAMACMD                      ; Call ADAM
              cmp   ADAMRTCD,'0"                  ; Open done OK?
              Jne    ERRRTN                           ; no - go process error
              .
              .
              .
    (There are some sequential mode Op Codes but they aren't really needed)
    The following are the Operation Codes that you can pass to ADAM:

    'O' - Open the ADAM file
    'C' - Close the ADAM file
    'R' - Read record by key or record number
    'Q' - Read record by partial key
    'N' - Read next record in order
    'D' - Read previous record (Read backward)
    'X' - Erase record (physical delete) can't be done on a record in a relative record number file
    'F' - Read the first record on the file
    'L' - Read the last record on the file
    'W' - Rewrite record
    'A' - Add record to the file

    Note that by using the 'L', and 'D' Op Codes you can process an ADAM file in reverse order, also you can create an ADAM file, add records in random order and read them back in order - works great as a SORT which I have used it for.

    I know you can do this in C# because the MicroSoft C# compiler accepts Assembly language code or, at least, it did way back when I tried C# and would much rather program in Assembly Language.

  8. #38
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    This may sound like a stupid question, but what is the difference between C and C#, if there is any? (I know that C++ is a more advanced language than C)

  9. #39
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> "Can you push the address of an ADAM control block onto the Stack and issue a Call to a subroutine in C#?"
    This sounds like you do need to support callbacks into whatever code is using your library. This is typically done by allowing the user to provide a stdcall function pointer to your library interface: Platform Invoke Tutorial (C#)

    >> The ADAM control block ...
    Any well-defined structures should be in the interface header as well. The above link shows how to map C structures in C# as well.

    >> ... but what is the difference between C and C#, if there is any?
    At a very high level, C/C++ compile directly into machine code and C# is based on the .NET framework - which means the code is compiled into "Common Intermediate Language" (CIL) and executed by the "Common Language Runtime" (CLR). .NET Framework - Wikipedia, the free encyclopedia

    Here's my guess at an updated header template:
    Code:
    // ADAM.h
    #ifndef ADAM_H
    #define ADAM_H
    
    #if defined(ADAM_IMPORT_LIB) /* if using an import lib for linking */
    #   define ADAM_API __declspec(dllimport)
    #else
    #   define ADAM_API
    #endif
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    /* ADAM operation codes */
    /* TODO - document parameters */
    #define ADAM_OC_Open        'O' /* Open the ADAM file */
    #define ADAM_OC_Close       'C' /* Close the ADAM file */
    #define ADAM_OC_Read        'R' /* Read record by key or record number */
    #define ADAM_OC_ReadPartial 'Q' /* Read record by partial key */
    #define ADAM_OC_NextRecord  'N' /* Read next record in order */
    #define ADAM_OC_PrevRecord  'D' /* Read previous record (Read backward) */
    #define ADAM_OC_Erase       'X' /* Erase record (physical delete) */
    #define ADAM_OC_FirstRecord 'F' /* Read the first record on the file */
    #define ADAM_OC_LastRecord  'L' /* Read the last record on the file */
    #define ADAM_OC_Write       'W' /* Rewrite record */
    #define ADAM_OC_Add         'A' /* Add record to the file */
    
    /* ADAM control block structure */
    #pragma pack(push, 1) /* MASM32 STRUCT's are packed by default */
    typedef struct
    {
        const char *filename;
        void *storage;
        unsigned __int64 storage_sz;
        int *key;
        int ret;
        char op;
        char prev_op;
        char file_open;
    } ADAM_CONTROL_BLOCK;
    #pragma pack(pop)
    
    typedef void (__stdcall *PFN_ADAM_CALLBACK)(ADAM_CONTROL_BLOCK *pcb);
    
    /* these interfaces would be called once per process (or per thread if need be) */
    ADAM_API int __stdcall ADAM_Init();
    ADAM_API int __stdcall ADAM_Shutdown();
    
    /* allow for multiple "ADAM instances" to be created and manipulated independently */
    ADAM_API int __stdcall ADAM_CreatHandle(const char *filename, void *pStorage, unsigned __int64 nSize);
    
    /* number of parameters depends on op */
    ADAM_API int __stdcall ADAM_Command(int handle, PFN_ADAM_CALLBACK cb, char op, ...);
                        /* ADAM_XXX ... */
    
    #ifdef __cplusplus
    }/* extern "C" */
    #endif
    
    #endif //ADAM_H
    gg

  10. #40
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    Quote Originally Posted by Codeplug View Post
    >> >> ... but what is the difference between C and C#, if there is any?
    At a very high level, C/C++ compile directly into machine code and C# is based on the .NET framework - which means the code is compiled into "Common Intermediate Language" (CIL) and executed by the "Common Language Runtime" (CLR). .NET Framework - Wikipedia, the free encyclopedia
    I guess I should have posted this thread on the C programming forum rather than the C# programming forum. In any event, ADAM is made up of ADAMCREA.exe, ADAMALDM.obj and ADAMACMD.obj as I posted before.

    How you use ADAM is to run ADAMCREA.exe to create your ADAM file. You can write an Assembly Language program to use it with the following code:

    Code:
    .data
    ADAMFILE LABEL BYTE
    AFILENAME DB 80 DUP(0)        ; PUT YOUR FILE NAME HERE
    AOPCODE DB 'O'       ; OPEN OPCODE
    ARETCODE DB '0'      ; RETURN CODE
    ALASTOP DB 'C'        ; LAST OPERATION PERFORMED
    AOPNCLS DB 'C'        ; OPEN CLOSED INDICATOR
    ABUFFER DD (OFFSET BUFFER)
    AKEYARG DD (OFFSET KEYARG)
                 .
                 .
    .code
    
    ADAMACMD PROTO
    
    .
    .
    LEA EAX,ADAMFILE
    PUSH EAX
    CALL ADAMACMD
    .
    .
    Compile and link the program that uses ADAMACMD as follows from the C:\ prompt:

    Code:
    ML /c /coff MYPROGRAM.asm
    link SUBSYSTEM/CONSOLE MYPROGRAM.obj ADAMACMD.obj
    using the MicroSoft MASM32 assembler and link edit programs.

    It sounds like a really complicated project to make it available to C programs!
    Last edited by Will1; 07-17-2014 at 03:59 PM.

  11. #41
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Here's where I found that "masm32 sdk" that contains the dll example code I mentioned earlier: MASM32 Home Page. Since I'm not familiar with masm32, I went to the example code to see how it does things.
    Code:
        .386
        .model flat, stdcall
        option casemap :none   ; case sensitive
    
    ;...
    
    TestProc proc
    
        jmp @F
          MbTitle db "Test function",0
          MbMsg db "TestProc here",0
        @@:
    
        invoke MessageBox,NULL,addr MbMsg,addr MbTitle,MB_OK
    
        ret
    
    TestProc endp
    Then link in this .obj and call it from a C app:
    Code:
    extern void __stdcall TestProc();
    int main() 
    {
        TestProc(); 
        return 0;
    }
    You should be able do the same with "ADAMACMD":
    Code:
    // ADAM.h
    #ifndef ADAM_H
    #define ADAM_H
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    /* ADAM control block structure */
    /* all members aligned naturally, so no packing needed */
    typedef struct
    {
        char AFILENAME[80];
        char AOPCODE;
        char ARETCODE;
        char ALASTOP;
        char AOPNCLS;
        void *ABUFFER; 
        int *AKEYARG;
    } ADAM_CONTROL_BLOCK;
    
    extern void __stdcall ADAMACMD(ADAM_CONTROL_BLOCK *pcb);
    
    #ifdef __cplusplus
    }/* extern "C" */
    #endif
    
    #endif //ADAM_H
    Code:
    #include "ADAM.h"
    // Link with ADAMACMD.obj
    int main() 
    {
        ADAM_CONTROL_BLOCK acb = {"data.dat", 'O', '0', 'C', 'C'};
        ADAMACMD(&acb);
        return acb.ARETCODE;
    }
    I think that should be equivalent to your asm call, assuming ADAMACMD is a stdcall function.

    gg

  12. #42
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Will1 View Post
    I guess I should have posted this thread on the C programming forum rather than the C# programming forum. In any event, ADAM is made up of ADAMCREA.exe, ADAMALDM.obj and ADAMACMD.obj as I posted before.

    How you use ADAM is to run ADAMCREA.exe to create your ADAM file. You can write an Assembly Language program to use it with the following code:

    Code:
    .data
    ADAMFILE LABEL BYTE
    AFILENAME DB 80 DUP(0)        ; PUT YOUR FILE NAME HERE
    AOPCODE DB 'O'       ; OPEN OPCODE
    ARETCODE DB '0'      ; RETURN CODE
    ALASTOP DB 'C'        ; LAST OPERATION PERFORMED
    AOPNCLS DB 'C'        ; OPEN CLOSED INDICATOR
    ABUFFER DD (OFFSET BUFFER)
    AKEYARG DD (OFFSET KEYARG)
                 .
                 .
    .code
    
    ADAMACMD PROTO
    
    .
    .
    LEA EAX,ADAMFILE
    PUSH EAX
    CALL ADAMACMD
    .
    .
    Maybe this is a stupid question, but since we're now on to asking lots of those, I'll chime back in here.

    How in the name of Odin is this better than SQL? ISO Standard SQL defines a common interface that many engines implement, with varying degrees of adherence. If you know SQL, you can store and retrieve data from any number of SQL implementations. You don't need to know assembly language. You don't need to know a proprietary API. In every implementation that I've seen, you don't even need to write a program to use SQL.

    Quote Originally Posted by Will1 View Post
    It sounds like a really complicated project to make it available to C programs!
    A rather interesting assumption from someone who doesn't even understand C well enough to know the difference between C and C#. The stdcall interface that has been mentioned a few times is very common in C on Win32, and passes parameters to functions by pushing them onto the stack, exactly the same way ADAM does.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  13. #43
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Will1
    I guess I should have posted this thread on the C programming forum rather than the C# programming forum.
    I have merged the topics into a single topic on the C programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #44
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> "Can you push the address of an ADAM control block onto the Stack and issue a Call to a subroutine in C#?"
    I just realized that you probably meant "how do you call ADAMACMD(&acb) in C#". I don't think you can link in a .obj directly. You would have to put it in a dll - which would only take some boilerplate code (from masm32/examples/exampl01/dll/tstdll.asm), a .def file, and modify your build cmd a bit. Then on the C# side, the link I posted earlier shows how to make a C# version of "ADAM_CONTROL_BLOCK" and call ADAMACMD() in the dll.

    gg

  15. #45
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    Quote Originally Posted by Elkvis View Post
    I don't really understand why you want to combine assembly language with C#/.Net. To me, it seems like a fool's errand. If you really want to do this, you could write your assembly language as inline assembly in a C++/CLI project (if it will let you), to produce what they call a "mixed-mode" assembly, which contains some native and some managed code. You would then reference that assembly in your C# project.

    Another option would be to make a fully native Win32 DLL containing your code, and use P/Invoke to call a function in it.

    It still doesn't make sense to do that, because the C++ compiler has gotten so advanced (since the DOS days), that it can probably generate better machine code, from C++, than your hand-written assembly language. I'm not trying to start a fight or belittle your abilities in assembly language, but C and C++ compilers have come a long way in the last 20 years. In my opinion, it would be better to just write an optimized C++ function to do what you want with the file.

    You're likely to get some raised eyebrows, and perhaps even some unkind words, as a DOS programmer, when you start telling people how their access methods "should have" been written. Tread lightly here.
    Elk - Sorry about the misunderstamding I've had with you. Now that I re-read the first Post on this thread, which you wrote, I realize that you probably gave me the best avice in that post that I've had so far. I guess the reason I didn't read that post thoroughly is because I felt you were criticizig Assembly Language and other posts distracted me. I apologize for being sarcastic. Assembly Language, like any language, is only as good as the person using it. I tried C many years ago (I think before WINDOWS was first released) and didn't like it. I liked the control of the computer that the DOS interrupts gave me. I'm an old mainframe Assembler Language programmer from way before the PC days so I never liked higher level languages. I'll grant you that C and C++ are far better languages than other high level languages but Assembly Language suits me far better. If I write a program for a computer I want the control that the DOS interrupts give me. If I program a computer, I want to "Program the Computer" if you know what I mean.

    It has been a chore making ADAM run under WINDOWS but I managed to make a very limited version of it run under WINDOWS. When I originally wrote ADAM, in the early 1980s using an IBM PCXT, I needed, what is called in mainframe lingo "Base" registers, and that is what the CS, DS, and ES are on a PC. WINDOWS won't let a program use them except in DOS mode. I used the DS: SI and ES: DI registers to communicate and pass data to and from a program that uses ADAM. I don't know why in HELL Microsoft wouldn't allow Assembly language to use the DS and ES registers under WINDOWS. Some people claim that it is because of "Protected Mode" but they are highly mis-informed. The mainframe has had "Protected Mode" ever since the 1960s and It didn't stop me from "Programming the Hardware" if you know what I mean.

    I really have little desire to help the ignorant populace of this planet but it appears that there are a few, a very few, (hopefully like you) who deserve better than those who govern this damned planet, including the USA, are giving us. Maybe you can help me make ADAM available, in a client/server environment, to programmers. Actually, I might be bettter off designing a server that runs DOS (version 6) and running the DOS version of ADAM. (The DOS version is capable of handling files up to 4 Gigabytes long.) I really don't want to learn C well enough to do the job but have, a few weeks ago, been diagnosed with cancer and don't know how much time I have left. Hopefully, for the benefit of the IS community, I have enough time to do it. You will note that I have little respect for the #%@hole people who are politicians. That very type of people have royally f#cked up this planet for a few thousand years now. Also, note that in my Webster's dicionary the word "scheming" is used in the definition of the word "politician."
    Last edited by Will1; 07-18-2014 at 12:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function call Overhead and Function Call Stack
    By Alam Khan in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2014, 08:28 AM
  2. Replies: 4
    Last Post: 10-03-2011, 06:30 AM
  3. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  4. Parameter in a function
    By cpluspluser in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2003, 07:48 PM