Why does this pointer throw Access violation?












0















I try to translate a pointer in my code.But it throw Access violation.



I tried many ways on the Internet,but they were all failed.



the main program:



createthread(nil,0,@make,@cli,0,tmp);//cli is a longint



and the procedure of make:



procedure make(a:pointer);
var
c:longint;
begin
c:=PLongint(a)^;
//here throw Access violation

...
end;


I expect to get the number in pointer a,how can I do this?










share|improve this question



























    0















    I try to translate a pointer in my code.But it throw Access violation.



    I tried many ways on the Internet,but they were all failed.



    the main program:



    createthread(nil,0,@make,@cli,0,tmp);//cli is a longint



    and the procedure of make:



    procedure make(a:pointer);
    var
    c:longint;
    begin
    c:=PLongint(a)^;
    //here throw Access violation

    ...
    end;


    I expect to get the number in pointer a,how can I do this?










    share|improve this question

























      0












      0








      0


      1






      I try to translate a pointer in my code.But it throw Access violation.



      I tried many ways on the Internet,but they were all failed.



      the main program:



      createthread(nil,0,@make,@cli,0,tmp);//cli is a longint



      and the procedure of make:



      procedure make(a:pointer);
      var
      c:longint;
      begin
      c:=PLongint(a)^;
      //here throw Access violation

      ...
      end;


      I expect to get the number in pointer a,how can I do this?










      share|improve this question














      I try to translate a pointer in my code.But it throw Access violation.



      I tried many ways on the Internet,but they were all failed.



      the main program:



      createthread(nil,0,@make,@cli,0,tmp);//cli is a longint



      and the procedure of make:



      procedure make(a:pointer);
      var
      c:longint;
      begin
      c:=PLongint(a)^;
      //here throw Access violation

      ...
      end;


      I expect to get the number in pointer a,how can I do this?







      windows pointers pascal






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 8:27









      zhuchengyangzhuchengyang

      234




      234
























          1 Answer
          1






          active

          oldest

          votes


















          2














          There are several things you need to do to successfully call a C function (like the Win32 CreateThread() API) from Pascal.



          One of them is set the correct calling sequence: stdcall.



          Other is get the pointers correct (your original question).



          Yet another issue is to make sure the C function declaration is capitalized correctly (e.g. CreateThread, not createthread.



          You haven't shown us your Pascal declaration, nor told us what Pascal compiler you're using.



          If you're using Borland Pascal, Delphi or FreePascal, look here for details on calling C from Pascal (and vice versa):



          http://www.drbob42.com/delphi/headconv.htm



          But if you're using any of those three Pascal's, consider finding an existing Pascal "thread" API, instead of creating your own wrapper.



          I hope that helps...






          share|improve this answer
























          • Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

            – Rudy Velthuis
            Jan 2 at 0:15











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994053%2fwhy-does-this-pointer-throw-access-violation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          There are several things you need to do to successfully call a C function (like the Win32 CreateThread() API) from Pascal.



          One of them is set the correct calling sequence: stdcall.



          Other is get the pointers correct (your original question).



          Yet another issue is to make sure the C function declaration is capitalized correctly (e.g. CreateThread, not createthread.



          You haven't shown us your Pascal declaration, nor told us what Pascal compiler you're using.



          If you're using Borland Pascal, Delphi or FreePascal, look here for details on calling C from Pascal (and vice versa):



          http://www.drbob42.com/delphi/headconv.htm



          But if you're using any of those three Pascal's, consider finding an existing Pascal "thread" API, instead of creating your own wrapper.



          I hope that helps...






          share|improve this answer
























          • Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

            – Rudy Velthuis
            Jan 2 at 0:15
















          2














          There are several things you need to do to successfully call a C function (like the Win32 CreateThread() API) from Pascal.



          One of them is set the correct calling sequence: stdcall.



          Other is get the pointers correct (your original question).



          Yet another issue is to make sure the C function declaration is capitalized correctly (e.g. CreateThread, not createthread.



          You haven't shown us your Pascal declaration, nor told us what Pascal compiler you're using.



          If you're using Borland Pascal, Delphi or FreePascal, look here for details on calling C from Pascal (and vice versa):



          http://www.drbob42.com/delphi/headconv.htm



          But if you're using any of those three Pascal's, consider finding an existing Pascal "thread" API, instead of creating your own wrapper.



          I hope that helps...






          share|improve this answer
























          • Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

            – Rudy Velthuis
            Jan 2 at 0:15














          2












          2








          2







          There are several things you need to do to successfully call a C function (like the Win32 CreateThread() API) from Pascal.



          One of them is set the correct calling sequence: stdcall.



          Other is get the pointers correct (your original question).



          Yet another issue is to make sure the C function declaration is capitalized correctly (e.g. CreateThread, not createthread.



          You haven't shown us your Pascal declaration, nor told us what Pascal compiler you're using.



          If you're using Borland Pascal, Delphi or FreePascal, look here for details on calling C from Pascal (and vice versa):



          http://www.drbob42.com/delphi/headconv.htm



          But if you're using any of those three Pascal's, consider finding an existing Pascal "thread" API, instead of creating your own wrapper.



          I hope that helps...






          share|improve this answer













          There are several things you need to do to successfully call a C function (like the Win32 CreateThread() API) from Pascal.



          One of them is set the correct calling sequence: stdcall.



          Other is get the pointers correct (your original question).



          Yet another issue is to make sure the C function declaration is capitalized correctly (e.g. CreateThread, not createthread.



          You haven't shown us your Pascal declaration, nor told us what Pascal compiler you're using.



          If you're using Borland Pascal, Delphi or FreePascal, look here for details on calling C from Pascal (and vice versa):



          http://www.drbob42.com/delphi/headconv.htm



          But if you're using any of those three Pascal's, consider finding an existing Pascal "thread" API, instead of creating your own wrapper.



          I hope that helps...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 1 at 8:38









          paulsm4paulsm4

          79.6k9101128




          79.6k9101128













          • Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

            – Rudy Velthuis
            Jan 2 at 0:15



















          • Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

            – Rudy Velthuis
            Jan 2 at 0:15

















          Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

          – Rudy Velthuis
          Jan 2 at 0:15





          Your "calling sequence" is generally called "calling convention". More on the subject in this article of mine: Pitfalls of converting.

          – Rudy Velthuis
          Jan 2 at 0:15




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994053%2fwhy-does-this-pointer-throw-access-violation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules