Re: [Tutor] Choice of tools

2018-05-10 Thread Brad M
Ya I am using that and the command line to compile at this point before I
can get VS to work for me again.
Thanks!!

On Thu, May 10, 2018 at 4:32 PM, Mark Lawrence 
wrote:

> On 09/05/18 10:10, Brad M wrote:
>
>> Hi all, I have a question about how to choose a proper IDE for C/C++
>>
>> I have been using visual studio ever since my C++ 101 days, but now I
>> realized there is a problem: feature lock-in!
>>
>> As an aside, I can't get "Error squiggles" to show up in my .c project in
>> visual studio 2017, where as in my .cpp project it promptly notifies me
>> of anything it doesn't like, such as printff("Hello world! \n );
>> Anyone know how to make it work for .c?
>>
>> So I have been happily letting MS VS 2017 community do my thinking
>> for me, so to speak, when it comes to error checking. Now I found out
>> I can't do any work since there isn't that Error squiggles feature for me,
>> I have to hunt down my next IDE!
>>
>> Well, Notepad++ has this really cool "VIM dark blue" theme that is
>> gorgeous! However, I am a lose for choosing my next editor/IDE...
>>
>>
>> 1) is it ok to get used to a feature that only some products feature
>> 2) is there anything else that has Error squiggles?
>> 3) recommend a C/C++ editor?
>>
>> Thanks all...
>>
>
> Check out Visual Studio Code as it's open source, is cross platform and
> supports most languages.
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Choice of tools

2018-05-09 Thread Brad M
Hi all, I have a question about how to choose a proper IDE for C/C++

I have been using visual studio ever since my C++ 101 days, but now I
realized there is a problem: feature lock-in!

As an aside, I can't get "Error squiggles" to show up in my .c project in
visual studio 2017, where as in my .cpp project it promptly notifies me
of anything it doesn't like, such as printff("Hello world! \n );
Anyone know how to make it work for .c?

So I have been happily letting MS VS 2017 community do my thinking
for me, so to speak, when it comes to error checking. Now I found out
I can't do any work since there isn't that Error squiggles feature for me,
I have to hunt down my next IDE!

Well, Notepad++ has this really cool "VIM dark blue" theme that is
gorgeous! However, I am a lose for choosing my next editor/IDE...


1) is it ok to get used to a feature that only some products feature
2) is there anything else that has Error squiggles?
3) recommend a C/C++ editor?

Thanks all...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calling printf() in a C language DLL using ctypes.CDLL

2018-05-09 Thread Brad M
Hmmm, I guess then it's time for me to ask this question: Is how I do this
the way you do it?

I have been inserting lines like this:   print("The program got here!")
all over my python code whenever I want to know where the program went.

If you want to know where your program went when something went wrong or
when it triggers a if condition, how do you do it?

Thanks!



On Wed, May 9, 2018 at 8:16 AM, eryk sun  wrote:

> On Tue, May 8, 2018 at 9:39 AM, Brad M  wrote:
> >
> > I compile this by typing this in the command line:
> > cl /LD /I C:\python\include helloworld.c C:\python\libs\python36.lib
>
> You're not using Python's C API, so you only need `cl /LD helloworld.c`.
>
> > However, this doesn't print anything on the python window.
> > What I would like is to do is to be able to use printf() in my .dll
> > by having the c code pop up a console window to print or
> > to have something that can print() in the python window somehow.
>
> By Python window, do you mean the IDLE GUI? If the library is loaded
> in a GUI program in which stdout is invalid, it will have to manually
> allocate a console via `AllocConsole` and open the screen buffer using
> the reserved filename "CONOUT$". Then it can print to the opened FILE
> stream using fprintf(). But I'll reiterate Alan here that this would
> be unusual behavior for a shared library, unless it's specifically
> intended as a UI library.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] calling printf() in a C language DLL using ctypes.CDLL

2018-05-08 Thread Brad M
Hi all:

I am trying out some c based module in a .dll file on windows.

// helloworld.c
#include 

__declspec(dllexport) void helloworld()
{
printf("Hello Everyone!!!");
}

I compile this by typing this in the command line:

cl /LD /I C:\python\include helloworld.c C:\python\libs\python36.lib

I get helloworld.dll for the above.



and the following is the python caller

import ctypes
mydll = ctypes.CDLL('helloworld')
mydll.helloworld()



However, this doesn't print anything on the python window.
What I would like is to do is to be able to use printf() in my .dll
by having the c code pop up a console window to print or
to have something that can print() in the python window somehow.

Is this possible?

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] passing values and C pointers

2018-05-06 Thread Brad M
Hi all:

Although I have college C++ 101 and Python 101 down my belt, I wan't
taught how to read a reference manual to figure this out :(

Say I have an array of values, say addresses or int produced by a c module/
c function that's in a DLL , how do I pass that array back to
the python code?

from ctypes import cdll
mydll = cdll.LoadLibrary('mydll')
a = mydll.c_get_data()


or, as I have learned in C, I can use malloc to create a linked list(new
beast for me) and then return the head pointer to the previous C function.

But eventually I am going to pass that C pointer back to python, right?
1) how do i do that,
2) how do do work on that data on that pointer? let's say the pointer
points to a linked list.

Thanks all!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python C extension - which method?

2018-05-06 Thread Brad M
Does this have any downside? I have noticed that printf("HI") in my .DLL;
doesn't really print anything.
I am on windows.

cdll.LoadLibrary('helloworld.dll')



My next question is that I need to return an array or a list of address or
int or some type of data, but
if I returned a pointer to the array of some data type, how does the python
cope with it?

For instance, my plan is to have 3 functions:

1) a function that return all addresses that have a given value to python,
say, 9001
2) then I do something with python so that values change, the target value
is now 1009.
3) a second function that takes all the addresses as input and then return
adddress that have values of 1009.

4) repeat 2 and 3 until there is only 1 or so of address which correct
values.
5) A 3rd function that takes only 1 address and simply return the values at
that address.

So the whole point of having 1-4 is to find the one address that contain
that values I want, and then
all I do is to call the 3rd function to find the values at that address.



So basically what I need to know is if the method I am using,
cdll.LoadLibrary('helloworld.dll')
is proper or I need some other method, and then I would like to find out
how to handle the data returned.
(address)

Thanks!!!



On Sun, May 6, 2018 at 5:44 AM, Stefan Behnel  wrote:

> Hi,
>
> Brad M schrieb am 04.05.2018 um 11:30:
> > I want to create a C-based memory scanner for Python, and so far this is
> > how I do it:
> >
> > Python:
> >
> > from ctypes import cdll
> > mydll = cdll.LoadLibrary('hello.dll')
> > print(mydll.say_something())
> >
> > and hello.dll:
> >
> > #include 
> > __declspec(dllexport) int say_something()
> > {
> > return 1980;
> > }
> >
> > so the printout is "1980"
> >
> > Is this alright?
>
>
> Depends on your needs and your C/C++ knowledge.
>
> If you have a shared library that provides the ready-made functionality,
> and accessing that native code at all is more important than calling it
> very quickly (e.g. you only do a few longish-running calls into it), then
> wrapping a shared library with ctypes (or preferably cffi) is a good way to
> do it.
>
> Otherwise, try either a native wrapper generator like pybind11, or write
> your wrapper in Cython.
>
> Specifically, if you are not just calling into an external library 1:1, but
> need to do (or can benefit from doing) non-trivial operations in native
> code, definitely use Cython.
>
> http://cython.org
>
>
> > I am aware that there is another much more complicated
> > method such as this:
> >
> > https://tutorialedge.net/python/python-c-extensions-
> tutorial/#building-and-installing-our-module
>
> Well, yes, it exists, but I advise against wrapping C code manually that
> way. It's just too cumbersome and error prone. Leave it to the experts who
> have already written their tools for you.
>
> Stefan
>
>
> Disclosure: I'm a Cython core dev, so I'm biased and I absolutely know what
> I'm talking about.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] ValueError: Procedure probably called with too many arguments (8 bytes in excess)

2018-05-06 Thread Brad M
Hi all:

I am experimenting with python calling some .DLL and this is my setup:

scan.py
memscan = ctypes.WinDLL('mahdll', use_last_error=True)
print(memscan.say_something(1,2))

# So I pass to int to the DLL function.


DLL:

#include 

__declspec(dllexport) int say_something(int a, int b)
{
printf("Hello World");
return math(a, b);
}

int math(int a, int b)
{
return a + b;
}




# So I found it wont print "hello world"
and it give this error:

ValueError: Procedure probably called with too many arguments (8 bytes in
excess)

# Also, if I pass no argument to the function, it won't printf("Hello
world")
on the python interpreter or opens a console window to print it.


So what's the right thing to do to pass arguments to a DLL function?

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python C extension - which method?

2018-05-06 Thread Brad M
If I may ask, what's the difference between these two?

1)
import ctypes
hello = ctypes.WinDLL('hello', use_last_error=True)

2)
from ctypes import cdll
hello = cdll.LoadLibrary('hello.dll')



Both of them can return "1980" from  this:

hello.c

#include 

__declspec(dllexport) int say_something()
{
return 1980;
}


On Sun, May 6, 2018 at 8:39 AM, Brad M  wrote:

> Does this have any downside? I have noticed that printf("HI") in my .DLL;
> doesn't really print anything.
> I am on windows.
>
> cdll.LoadLibrary('helloworld.dll')
>
>
>
> My next question is that I need to return an array or a list of address or
> int or some type of data, but
> if I returned a pointer to the array of some data type, how does the
> python cope with it?
>
> For instance, my plan is to have 3 functions:
>
> 1) a function that return all addresses that have a given value to python,
> say, 9001
> 2) then I do something with python so that values change, the target value
> is now 1009.
> 3) a second function that takes all the addresses as input and then return
> adddress that have values of 1009.
>
> 4) repeat 2 and 3 until there is only 1 or so of address which correct
> values.
> 5) A 3rd function that takes only 1 address and simply return the values
> at that address.
>
> So the whole point of having 1-4 is to find the one address that contain
> that values I want, and then
> all I do is to call the 3rd function to find the values at that address.
>
>
>
> So basically what I need to know is if the method I am using,
> cdll.LoadLibrary('helloworld.dll')
> is proper or I need some other method, and then I would like to find out
> how to handle the data returned.
> (address)
>
> Thanks!!!
>
>
>
> On Sun, May 6, 2018 at 5:44 AM, Stefan Behnel  wrote:
>
>> Hi,
>>
>> Brad M schrieb am 04.05.2018 um 11:30:
>> > I want to create a C-based memory scanner for Python, and so far this is
>> > how I do it:
>> >
>> > Python:
>> >
>> > from ctypes import cdll
>> > mydll = cdll.LoadLibrary('hello.dll')
>> > print(mydll.say_something())
>> >
>> > and hello.dll:
>> >
>> > #include 
>> > __declspec(dllexport) int say_something()
>> > {
>> > return 1980;
>> > }
>> >
>> > so the printout is "1980"
>> >
>> > Is this alright?
>>
>>
>> Depends on your needs and your C/C++ knowledge.
>>
>> If you have a shared library that provides the ready-made functionality,
>> and accessing that native code at all is more important than calling it
>> very quickly (e.g. you only do a few longish-running calls into it), then
>> wrapping a shared library with ctypes (or preferably cffi) is a good way
>> to
>> do it.
>>
>> Otherwise, try either a native wrapper generator like pybind11, or write
>> your wrapper in Cython.
>>
>> Specifically, if you are not just calling into an external library 1:1,
>> but
>> need to do (or can benefit from doing) non-trivial operations in native
>> code, definitely use Cython.
>>
>> http://cython.org
>>
>>
>> > I am aware that there is another much more complicated
>> > method such as this:
>> >
>> > https://tutorialedge.net/python/python-c-extensions-tutorial
>> /#building-and-installing-our-module
>>
>> Well, yes, it exists, but I advise against wrapping C code manually that
>> way. It's just too cumbersome and error prone. Leave it to the experts who
>> have already written their tools for you.
>>
>> Stefan
>>
>>
>> Disclosure: I'm a Cython core dev, so I'm biased and I absolutely know
>> what
>> I'm talking about.
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python C extension - which method?

2018-05-05 Thread Brad M
Hi all:

I want to create a C-based memory scanner for Python, and so far this is
how I do it:

Python:

from ctypes import cdll
mydll = cdll.LoadLibrary('hello.dll')
print(mydll.say_something())



and hello.dll:

#include 
__declspec(dllexport) int say_something()
{
return 1980;
}


so the printout is "1980"


Is this alright? I am aware that there is another much more complicated
method such as this:

https://tutorialedge.net/python/python-c-extensions-tutorial/#building-and-installing-our-module



Is my method alright?

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor